Mackelito
Mackelito

Reputation: 4421

jquery selector performance?

Just curious about which of these would be faster?

$('ul.dropdown a').first().click(function(event) {
    event.stopPropagation();
    return false;
});

or

$('.dropdown > li > a').click(function(event) {           
    event.preventDefault();
});

Is there any difference?

Upvotes: 0

Views: 54

Answers (2)

Thulasiram
Thulasiram

Reputation: 8552

$('.dropdown').find('a').on('click', function(e) {           
    e.preventDefault();
});

Upvotes: 0

gdoron
gdoron

Reputation: 150253

They do two different things.

I guess you're asking about > V.S. space:
> is fatser then space, as it goes one level deep only.

The tip with selectors is make the right side of it more precise than the left.
Read more here

Upvotes: 1

Related Questions