so in my page I’ll be inserting a series of elements, let’s say with class name “element” but some of them will be disabled, which will get additional class “disabled”. Now I want to bind a click event to all non-disabled elements, and I was just wondering if performance wise it’s better to just write
$(".element:not(.disabled)") .live("click",function() { ...
or should I bind a click event to each individual elements as they are being inserted ?
p.s. I know .on has replaced .live, but right now im using version 1.6.2, so can’t change that
First off, you should never be using
.live()any more as it has been deprecated for all versions of jQuery. I would suggest this:There should be little performance issue with this because the comparison to the selector only happens when a click occurs and when the comparison is done, it’s a fairly simple comparison to just the check the target’s class name.
Also, since a click is a user action that occurs in user time and the selector comparison is not complex at all, it is highly unlikely that any delay could be noticable (we’re talking about milliseconds here at most).