Hello, I am building a plugin and need to use live() to capture click events on elements with a configurable class name, but only if they are children of specific node (that may or may not have an ID).
For example, I want to create several containers (divs) on the page, and if any element with a class name of "close" within the container is clicked, it should remove the container. I tried this using live(): var createContainer = function() { var container = $('<div></div>'); container.find('.close').live(function() { container.remove(); }); container.append('<span class="close">[close]</span>'); $(document.body).append(container); }; The code works if there's only one container on the page. But if I create 2 or more containers, clicking the [close] on any of them will close all of them. It seems that live() is firing for any element on the page that contains a close class, but I only need it to fire in the container that was clicked. I cannot use bind() or click() because the containers can be modified after they are created and all elements that contain the class "close" should close the container. Any workarounds for this? Do I have to write my own event delegation code to get this to work? Thanks for the help! -- Hector