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

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

Thank you very much, Airshow!!! Exactly what I need!)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.