Hey all

How can I when dynamically adding a new element also bind a click event to
another element which removes it?

//Here's what I have so far, redundant code is omitted

$.fn.addElement = function(options) 
{
    //Redundant code omitted
    this.prepend($elementToAdd); //dynamically create a new DIV
    $removingElement.click(function() 
    {
        $elementToAdd.remove();
    });
}

What happens is that jQuery somehow holds references to all of the added
elements and in case of a $removingElement.click removes all of them. I want
to bind the $removingElement.click only to the element created at that
certain addElement function call. Any ideas?

Thanks!
-- 
View this message in context: 
http://www.nabble.com/Removing-dynamically-added-elements-tp15502425s27240p15502425.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to