Live Query jQuery plugin. Ingenious plugin that lets you register jQuery event bindings to be executed when a new element matching the provided selector is added to the DOM. Performance is kept snappy by only running the check after a jQuery DOM manipulation method has been executed (append, prepend, attr etc); it won’t notice elements added using regular DOM methods.
Seems to me you could fix that problem by adding the event handler to the document and relying on bubbling.
Jim - 23rd August 2007 00:24 - #
Fantastic article. I seem to end up writing a function that checks to see if methods are already applied to a set of elements, and if not applies my functions. Then when I add new items to the DOM via .append et al, I re-call my function. Yuck.
Nice find!
Why not give a try to "jQuery live bind"?
You even could use it like this(bind an element before create it):
$.live_bind(".kkkk .ppp[title='333']:nth-child(3)", 'click', alr1);
$('.kkkk').append('<div class="ppp" title="333">hello</div>');
http://plugins.jquery.com/project/live_bind
diyism - 16th September 2008 07:36 - #