Home    Articles

 

jQuery Events not triggered on new added html elements

 

Becouse the dynamically created elements are not that easy to be used with document.getElementBy

You can use .live() or .on()
Examples:

$('#my_div_id').live( eventName, function(){} );

Or

$(document).on( eventName, '#my_div_id', function(){} );

eventName = click, submit, dblclick, focus, mouseover ...etc

ps: it is highly recomended to use .on() insted of .live().
the .live() is deprecated in version 1.7 in favor of .on() and it was deleted in version 1.9.
…here is a link so you can get a better look: jQuery .live()
Enjoy.

by