Problem while detaching an event with an element
Hi,
I have a <a> element to which i am attaching a click event.This element is created inside a <div>.
I am attaching each div a unique id during its creation time.This is not a static div and is created dynamically.
This <a class="icon"> provides an image for removing the <div>.
The problem now is
eg:i am creating the div as <div id=divid><a class="icon"></a></div>.At this time i am attaching the event to the <a> as follows
jQuery('#'+divid+' .icon').live('click',function(){
jQuery(this).die();
jQuery(this).parent().remove();
});
Here divid is a variable.Let its value=1;
I am again creating another div with id=2 with same structure above and event attachment procedure same as above.
After that i remove the div with id=2 using the image provided by <a class="icon">.
I again added a div with id=2 and same structure above and attaching the event for that div as above.
Now we have only one div with id=2.
When i remove the div with id=2,two times the click event is getting triggered.
I think eventhough i removed the first div with id=2,the events are not getting destroyed.I think that is why this behaviour occurs.
please provide any solution
~Ragesh Kumar A.K