doremi
doremi

Reputation: 15349

jQuery: Loop through all elements within two IDs

I'm trying to loop through each .required within two divs: #A and #B.

$('#A .required').nextUntil('#B').each(function() {
    console.log($(this).attr("name"));
});

The above only seems to get the last element within the two divs. How can I fix this?

Upvotes: 0

Views: 373

Answers (1)

Pointy
Pointy

Reputation: 414046

Not exactly sure I understand the HTML behind this, but maybe you want:

$('#A .required, #B .required').each(function() { ... });

That gets all the elements marked with class "required" that are descendants of either the element with id "A" or the one with id "B".

Upvotes: 1

Related Questions