All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S2715.html Maven / Gradle / Ivy

The use of find allows document.getElementById() to be used for the top-level selection, and saves the 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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy