Riju
Riju

Reputation: 1

how can i swap arrray of same images using jquery.

<img src= on.jpg id=1>
<img src= on.jpg id=2>
<img src= on.jpg id=3>
<img src= on.jpg id=4>
<img src= on.jpg id=5>
<img src= on.jpg id=6>

on each image clik i need to get off image ie,

if click on first image then i need to swap that on.jpg image with off.jpg and remains are in same on.jpg

and update this value into the MSQL DB..

img_id image
1     off.jpg
2     on.jpg
3     on.jpg
4     on.jpg
5     on.jpg
6     ofn.jpg

Upvotes: 0

Views: 58

Answers (1)

Raul Agrait
Raul Agrait

Reputation: 6018

$("img").click(function(event){
  var isOn = (this.src == "on.jpg");
  var newSource = (isOn) ? "off.jpg" : "on.jpg";
  this.src = newSource;
  // Update your MSQL DB using presumably this.id and newSource
});

Upvotes: 1

Related Questions