How would I write both of these without using .each() and only using JQuery Selectors?
var xxxx = 0;
$('.clonedInput').each(function(index) {
if($(this).children().filter(':checked').length == 2)
xxxx++;
});
var num_normal_foods = 0;
$('[id^="amount_"]').each(function(index) {
if($(this).val() == '30.00')
num_normal_foods++;
});
Lets take this one step at a time.
You started with:
To me this looks like you’re simply trying to
filtera collection of.clonedInputelements and find out how many match the filter:Followed by:
Again, this looks like a filtering function to me:
In the end, what matters is that the code does what you intend it to do. If the code you wrote with
.eachdoes what you want it to, then there’s no need to change it. Behind-the-scenesfilteruseseachanyway.