I'm looking for any way that I can improve the selector performance of a jQuery call. Specifically things like this:
Is $("div.myclass")
faster than $(".myclass")
I would think it might be, but I don't know if jQuery is smart enough to limit the search by tag name first, etc. Anyone have any ideas for how to formulate a jQuery selector string for best performance?
ID and Element selector are the fastest selectors in jQuery.
Ofceauce ID is a faster selector in both CSS and JavaScript.
There is no doubt that filtering by tag name first is much faster than filtering by classname.
This will be the case until all browsers implement getElementsByClassName natively, as is the case with getElementsByTagName.
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