I am reading the jQuery API, about even selector, jQuery recommend we select a list of elements use pure CSS Selector and then use filter(":even") for better performance. But I think jQuery optimized for their :even selector too. When I used any selector, it gave me the same result with the same time. Will it have different only when we have more than 1 million of elements?
Could someone please explain how the :even selector work and why use filter(":even") is better?
Thanks, Tho Vo
Why not test it? http://jsperf.com/even-selector
If you're looking for something fast, use :nth-child(even), as it's a native selector and can be fed into document.querySelectorAll. :even is a jQuery-specific pseudo-selector and forces jQuery to traverse the DOM using JavaScript, which will almost always be slower than document.querySelector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With