0

Hi everybody,

I have a js(using jQuery lib) file where all events and following actions(functions) are written.
For one of such events there is a function that prepends one more similar element from which prepending was called:

$("#id1").click(function(){
$(...).before("<div id='id1'></div>");
});

so that when I will click to just prepended element one more element should be prepended and so on.

The problem is that when new element is prepended, click event doesn't work on it. jQuery doesn't recognize it, like doesn't see it. How to fix it?

Thnx in advance

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Acute
0

Acute,

$(sel).click(...) attaches functionality only to matching elements that exist when the command is executed.

Use $(sel).live(...) to attach functionality to existing matching elements and any future elements that also match sel.

Airshow

Edited by Dani: Formatting fixed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.