3

I have one img div. Onclick on it, AJAx inserts into database smthng. I want to change img add.png to added.png on click.

First click: add.png -> added.png
Next click: added.png -> add.png etc.

I try:

success: function(){
    $('.paste_here').html("<img src=\"add.png\">");
}

So, how can I do to change the add to added and added to add on each click in success part???

  • 1
    The sample given here http://stackoverflow.com/questions/554273/changing-the-image-source-using-jquery does exactly what you want. – Digifaktur Jan 14 '15 at 12:07

2 Answers2

1

1: define a flag

var flag=true;

2: check for flag and then decide what to call(add.png or added.png).

success: function(){
 if(flag){
      $('.paste_here').html("<img src=\"added.png\">");
      flag=false
        }
 else{
     $('.paste_here').html("<img src=\"add.png\">");
     flag=true
     }
}
Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
  • That's not me. I upvote it. But do not accept yet. I will try it later when I can –  Jan 14 '15 at 12:12
0

Will using this work?

success: function(){
    $('.paste_here').html("<img src=\"added.png\">");
}
VeldMuijz
  • 605
  • 5
  • 18