28 lines
959 B
Plaintext
28 lines
959 B
Plaintext
The use of ``++find++`` allows ``++document.getElementById()++`` to be used for the top-level selection, and saves the jQuery Sizzle engine for where it's really needed. That makes the query faster, and your application more responsive.
|
||
|
||
|
||
From the jQuery documentation:
|
||
|
||
|
||
____
|
||
Beginning your selector with an ID is always best.
|
||
|
||
The ``++.find()++`` approach is faster because the first selection is handled without going through the Sizzle selector engine – ID-only selections are handled using ``++document.getElementById()++``, which is extremely fast because it is native to the browser.
|
||
|
||
____
|
||
|
||
|
||
== Noncompliant Code Example
|
||
|
||
----
|
||
var $productIds = $("#products div.id"); // Noncompliant - a nested query for Sizzle selector engine
|
||
----
|
||
|
||
|
||
== Compliant Solution
|
||
|
||
----
|
||
var $productIds = $("#products").find("div.id"); // Compliant - #products is already selected by document.getElementById() so only div.id needs to go through Sizzle selector engine
|
||
----
|
||
|