jQuery - how to undo prepend

Ankur picture Ankur · Aug 12, 2009 · Viewed 19.4k times · Source

I am using the prepend() function to diplay an image when a div is hoevered over. How do I remove the image - i.e. what is the opposite of prepend()

Here is the code:

$("#hover-div").hover(
        function() { $("#image-div").prepend("<img src='images/arrow_redo.png' width='16' height='16' />"); },
        function() { $("#image-div").someFunction("<img src='images/arrow_redo.png' width='16' height='16' />"); }
        );

someFunction is just a dummy - I am not really expecting it to do anything.

Answer

rahul picture rahul · Aug 12, 2009

If you have the id for the image element you can simply use the remove method.

$("#imgID").remove();