JQuery: how to use "delegate" instead of "live"?
Posted
by JacobD
on Stack Overflow
See other posts from Stack Overflow
or by JacobD
Published on 2010-04-29T15:53:03Z
Indexed on
2010/04/29
16:47 UTC
Read the original article
Hit count: 234
I've read countless articles how using the JQuery delegate is much more efficient than using the "live" event.
As such, I'm having trouble converting my existing Live code to using Delegate.
$("#tabs li:eq(0)").live('click',function(){ //...code });
$('#A > div.listing, #B > div.listing, #C > div.listing').live('mouseover',function(){ // ...code });
When I replace the previous code with what I assume is more efficient delegate code, my page doesn't load.
$("#tabs li:eq(0)").delegate('click',function(){ //...code });
$('#A > div.listing, #B > div.listing, #C > div.listing').delegate('mouseover',function(){ // ...code });
Any idea why my delegate code doesn't work? Also, any suggestions on how to make this more efficient?
UPDATE:
The think part of the problem is that, both "#tabs" and "#A, #B, #C" are't present on the web page at page load. Those attributes are dynamically inserted onto the page with an AJAX call. As such, does that mean I have to use live over delegate?
© Stack Overflow or respective owner