tags:

views:

262

answers:

3

Hi,

I have added a image using the statement $(this).parent().siblings().children('#control).before("");

On click of another button I want to remove the appended image.

How to do it. Need help.

+1  A: 

Give it an ID or suitable identifier such as a class, then remove it by selector:

$('#img').remove();//by id
$('.myImg').remove();//by class
karim79
A: 

Hi, I haven't tested this, but I know of the prev() function, so assuming you don't prepend that image more than once, maybe try:

$(this).parent().siblings().children('#control).prev().remove()
Neil Fenwick
Its working dude. Thanks a lot.
+2  A: 

There are multiple ways of doing so:

  • Give the image an ID
  • Give the image a class
  • Keep a reference to the image

Then just use whichever selector is needed for the method you choose and call:

$('#uniqueID').remove();
$('.className').remove();
imageReference.remove(); // if you did var imageReference = $(this).parent().siblings().children('#control).before("");
GoodEnough