28 lines
959 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
____
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
var $productIds = $("#products div.id"); // Noncompliant - a nested query for Sizzle selector engine
----
2021-04-28 16:49:39 +02:00
== 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
----