You can use .each()
and depending on what operations you want to run you can for example use if
and if else
statements.
$("#subitem > div").each(function() {
if (this.id == "first") {
console.log("found div with id " + this.id)
} else if (this.id == "two") {
console.log("found div with id " + this.id + ", and it's the second div")
}
});
Demo
$("#subitem > div").each(function() {
if (this.id == "first") {
console.log("found div with id " + this.id)
} else if (this.id == "two") {
console.log("found div with id " + this.id + ", and it's the second div")
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="item">
<div id="subitem">
<div id="first"></div>
<div id="two"></div>
</div>
</div>