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.
Tags: jQuery
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
- http://URL(Optional) Shaun
- http://www.jhaygamba.com Jhay
- http://webdevvote.com WebDevVote
- http://danielfarrell.com/blog/ Daniel
- http://aetus.net/ celebrus
- http://jewepasch.de Jewe
- http://www.sachagreif.com Sacha
- http://thoughtboxcreative.com Darren
- http://james.padolsey.com James
- http://www.joeholdcroft.com Joe Holdcroft
- http://www.as7ap4you.com kareem
- http://www.cere.be Cerebral
- http://thelucid.com Jamie Hill
- http://corn-man.blogspot.com Sudhir
- http://www.chrisgunther.net Chris Gunther
- gogi
- http://www.conspiratordesign.com Christopher
- http://latower.com Gilles Ruppert
- http://www.kayoooe.com Jmmm
- Nate
- http://www.reklame-groningen.nl/ Groningen
- http://www.fonroots.com Electric Graffiti
- oyanamoy
- http://blueco.ir/ طراحی سایت و سئو

