O'Reilly logo

jQuery Essentials by Troy Miles

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

jQuery selectors

The first thing to understand about selectors is that they are a call to the browser's Document Object Model, or DOM, and that all interactions with the DOM are slow. Even developers who know the DOM is slow sometimes don't understand that jQuery uses the DOM like all of the code, which renders the markup to the browser page. Selectors are at the heart of jQuery, and small differences in selectors can make big differences in the speed of the code. It is important for us to understand how to write selectors that are fast and efficient.

Using IDs over other selectors

The fastest selectors are those that are based on the fastest underlying DOM code. A fast DOM-based element finding method is document.getElementById(), so it follows ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required