Well, a (web) developer should give user experience priority to those two, but as you mentioned in my case, which is about a smaller group of elements, it probably won't make any difference. However, I'm grateful of the hints, including the improvement in version 1.2.6 which I had no idea of, since this might be of use in much larger projects of mine.
On Thu, Jun 12, 2008 at 12:41 AM, Josh Nathanson <[EMAIL PROTECTED]> wrote: > You are sacrificing a small bit of performance for a world of easier code > development and maintenance. In nearly all cases it's a worthwhile trade. > > If you had 1000 or more divs you'd probably not want to use each() to bind > the handlers, but for any reasonably small number of elements, the > performance hit is ok. Plus, binding speed has been improved in jQuery > 1.2.6. > > -- Josh > > > ----- Original Message ----- > *From:* Isaak Malik <[EMAIL PROTECTED]> > *To:* jquery-en@googlegroups.com > *Sent:* Wednesday, June 11, 2008 1:56 PM > *Subject:* [jQuery] jQuery.each() or element event triggers? > > Dear list, > > I'm not really into the code of the jQuery core so I'm not sure of how > jQuery.each() works, but I'm wondering: since jQuery.each() loops through > every element that matches the given selector is my logics right that is it > better performance wise to use static element event trigger instead of using > the each() method on all the elements? > > An example for the simple-minded: > > $('div').each(function(){$(this).click(function(){alert('You clicked me: ' > + this.id + '!')})}) > > or > > <div id='blabla1' onclick="alert('You clicked me: ' + this.id + > '!')"></div> > <div id='blabla2' onclick="alert('You clicked me: ' + this.id + > '!')"></div> > <div id='blabla3' onclick="alert('You clicked me: ' + this.id + > '!')"></div> > > ? > > In most cases it does take more characters for the same functionality but > what are the differences in performance? > > Kind regards, > -- > Isaak Malik > Web Developer > > -- Isaak Malik Web Developer