In the second one, myEl is already a jQuery object, so there's no
reason to wrap it in $(), you could just use myEl.each(). However,
since all you're doing is adding a handler for the click event,
there's no reason to iterate over the elements so the first one is
most appropriate.

On Mar 4, 7:06 am, hcvitto <hcvi...@gmail.com> wrote:
> right..thanks
>
> On Mar 4, 3:38 pm, MorningZ <morni...@gmail.com> wrote:
>
> > Well, the second version won't help very much since you are not
> > reusing "myEL" later on
>
> > On Mar 4, 9:36 am, hcvitto <hcvi...@gmail.com> wrote:
>
> > > hi
> > > just needed an advice...
> > > what' s better between this two (if there's any difference at all):
>
> > > this:
>
> > > $('a[class^=open]').click(function(){
> > >     ...whatever...
>
> > > });
>
> > > or this:
>
> > > var myEl = $('a[class^=open]');
> > > $(myEl).each(function(){
> > >      $(this).click(function(){
> > >         ...whatever...
> > >      });
> > > )};
>
> > > thanks
> > > Vitto

Reply via email to