In IntelliJ, if I use a jQuery selector such as:
$('#roleField option').each(function() {
// impl omitted
});
The selector is highlighted with a suggestion that I should
split descendant selectors which are prefaced with ID selector
what exactly is IntelliJ suggesting that I should replace the selector above with?
ID and Element selector are the fastest selectors in jQuery.
Ofceauce ID is a faster selector in both CSS and JavaScript.
A. When it comes to speed, jQuery is quite fast for modern browsers on modern computers. So is pure JavaScript but both run very slow on older browsers and machines. Pure Javascript functions will be faster than jQuery operations.
From the jquery documentation this method will not go through the Sizzle sector engine:
$('#roleField option').each(function() {
// No Sizzle
});
Where this one will:
$('#roleField').find('option') // Sizzle!
Look at the ID base selectors section here. Hence the second method will be faster than the first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With