I have a DOM structure similar to this:
<div id="ans1">
<input id="in1" />
<input id="in2" />
</div>
<div id="ans2">
<input id="in1" />
<input id="in2" />
</div>
How can I select some of the descendants of an ancestor?
Something like:
$("#ans1 #in1, #ans1 #in2")
If you replace your 'id's with classes (since ids should be unique), then,
Then, to select all the descendants of id=ans1 having class="in1", you go like,
This will return an array of all the .in1 class elements inside id=ans1 element
You can use the children function
You should use unique ids thought the DOM, use classes to specify elements that are the same in nature.
change your children to have same class of in1
Will select all direct descendants of ans1 with class of in1.