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?
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?
Share Improve this question asked May 7, 2014 at 12:38 DónalDónal 187k177 gold badges584 silver badges843 bronze badges 10 | Show 5 more comments2 Answers
Reset to default 19From 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.
Try to use .find()
here:
$('#roleField').find('option').each(function() {
// impl omitted
});
Your warning seem like related to efficiency of the selector.
Related thread
$('#roleField').find('option')
– Arun P Johny Commented May 7, 2014 at 12:39$('#roleField').find('option').each()
– Reinstate Monica Cellio Commented May 7, 2014 at 12:39.find
unless it's on an assigned variable. If I have aselector
, like you show above, I just do exactly what you're doing,$('#id child')
. There's really no reason to replace it with$('#id').find('child')
– SpYk3HH Commented May 7, 2014 at 12:46getElementById()
to fetch first record... – Arun P Johny Commented May 7, 2014 at 12:46