In my web application I have around 10 headings with same class name, so when a user click on that a loading image will be appended to them and some data will be filled via ajax in a div then after this whole processing i just want to remove that loading image.
Here is my code:
jQuery('.replyhead').live('click',function(){
var idval=jQuery(this).attr('id');
jQuery(this).append('<img src="images/loading.gif"/>');
jQuery.post('abc.php',{rack:idval},function(data) {
jQuery('#r'+idval).html(data);
//now here i just need to remove that loading.gif
});
});
Any recommendations on how to do this?
Instead of using
append()create an element using thejQueryconstructor, useappendToto append it. Later, you can useimg.remove()(or whatever variable name you’ve chosen) to rmeove the image.An alternative method would consist of attaching an unique ID to the image, and use
$("#uniqueIDhere").remove()to remove the element. This method will break when you’re not properly defining unique IDs though.(Taken from the answer below, showing relevant parts only):