dbzz, IMO, your code still add a listener to each of the .headline

var txt = $('.article-text');
var $hl = $('.headline');

$hl.click(function(e) {
        $(txt[$hl.index(e.target)]).fadeIn();
});

I highly doubt that this code will run faster than the one using each.

On Dec 22, 9:20 am, dbzz <j...@briskey.net> wrote:
> and if you have _really_ a lot of elements...
> instead of a listener on each, just use one -
>
> var $hl = $('.headline');
> $hl.click(function(e) {
>         $('.article-text').eq( $hl.index(e.target) ).fadeIn();
>
> });
>
> On Dec 21, 5:57 am, Kean <shenan...@gmail.com> wrote:
>
> > Some performance improvement, especially if you have a lot of
> > elements.
>
> > var txt = $('.article-text');
>
> > $('.headline').each(function(i) {
> >   $(this).click(function() {
> >     $(txt[i]).fadeIn();
> >   })
>
> > });

Reply via email to