I’m trying to loop through an array of dom elements and only return the dom element if it matches a specific criteria. In the case below if the id attribute is equal to the value of “0” and it has a child element with the class name record.
I have tried the below code but it returns element 0 always even if it does not have a child with the class record.
var el = shows.map(function(index, element) {
if (this.id == "0" && $(element).children('.record')) return this;
});
Change
$(element).children('.record')to$(element).children('.record').length.If jQuery doesn’t find any elements, it returns an empty array, which JavaScript converts to
true.