Joel Crawford-Smith
Joel Crawford-Smith

Reputation: 494

Which selector is faster?

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

Answers (2)

user479911
user479911

Reputation:

$('a[rel="something"]').length > 0) is faster.

Upvotes: 1

Sarfraz
Sarfraz

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

Related Questions