2 ms·
don't do that on IE where there are potentially a lot of <a>-tags. IE behaves really, really badly once a selector matches a large amount of elements (there mus
by pilif 16y ago
don't do that on IE where there are potentially a lot of <a>-tags. IE behaves really, really badly once a selector matches a large amount of elements (there must be something O(n^2) going on somehwere).
This is what delegate() was invented for.
$(document).delegate('a.nodefault', 'click', function(e){
e.preventDefault();
}
I'm using a .nodefault class selector such that it applies only to links marked with class="nodefault" - you might want to have links that should work normally.
If you're using HTML5, using a data-yourapp-nodefault=true attribute might be even better as you shouldn't overload classes.
Incidentally, returning false; in a directly bound handler (which is was the original article was talking about) prevents exactly this suggestion here from working as the delegated handler on document would never see the click.