I have a list of
You need to bind the event handler to a common ancestor of the elements on which it should be triggered. For example, if your This would be for an HTML structure like so: The reason this works is that DOM events bubble up the tree from the point at which they originate. The Also note that it's invalid to have duplicate Finally, if you are using jQuery 1.7+ you should use the on method instead. It will have the same effect, but notice the reversal of the first 2 arguments:
#element
gets appended inside a div
with an id
of parent
:$("#parent").delegate(".commenticon", "click", function() {
//Do stuff
});
delegate
method captures the event at an ancestor element and checks whether or not it originated at an element matching the selector.id
values in the same document. Here I've changed your element
ID values to class names instead.$("#parent").on("click", ".commenticon", function() {
//Do stuff
};