Reputation: 494
I'm searching for the existance of one matching selector. Which is faster?
$('a[rel="something"]').first().length > 0)
or
$('a[rel="something"]').length > 0)
Thanks!
Upvotes: 0
Views: 76
Reputation: 382666
$('a[rel="something"]').length > 0)
should be faster because it does not have overhead of picking up (finding out) the first()
element in the wrapped set $('a[rel="something"]')
.
And if you are targeting one element with $('a[rel="something"]')
, using first()
isn't needed anyway.
Upvotes: 6