If you've ever dynamically created an element using Javascript, you'll no doubt have experienced problems with binding events to these elements. Luckily, a small jQuery plugin created by Brandon Aaron (jQuery team member), called Live Query, makes this a cinch.
"Live Query utilizes the power of jQuery selectors by binding events or firing callbacks for matched elements auto-magically, even after the page has been loaded and the DOM updated."
Implementation
$('a') .livequery('click', function(event) { alert('clicked'); return false; });
This will fire the click event on all anchor tags - even the ones that have been dynamically generated with AJAX. For more information, refer to the documentation.
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Update me weeklyEnvato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!
Translate this post