Web Development with jQuery®

(Elliott) #1

Appendix B (^) ❘ 499
bapp02.indd 02/17/2015 Page 499
Note that selectors marked with an asterisk (*) are jQuery extensions to the standard Selector
API, which utilizes the built-in browser Selector API document.querySelector() and
document.querySelectorAll()and may not perform as well as natively supported selectors.
Wherever possible, jQuery’s selector engine, Sizzle, transforms these extended features into natively
supported selectors at run time, so in many cases the performance impact is negligible, but there is
still the additional overhead of parsing the selector and transforming the selector into one that the
native selector API understands.
Having said that, to get the best possible performance out of jQuery, it is best to fi rst perform a
selection using a highly effi cient selector (the most effi cient selector is an id selector), and then fi lter
the selection from within the context of that selection using fi ltering methods such as find(),
filter() , and so on. This is good practice not just for jQuery extensions to the selector API but for
any selection. Id selectors are the most effi cient selectors because ids are meant to be unique (you
should never assign the same id name to multiple elements) and, when done correctly, id selections
result in only one possible match within a document.
http://www.it-ebooks.info

Free download pdf