Reputation: 11
I need to find a certain class and then find an input which is nested a number of elements below it. I need the target classes name as to append it.
I thought i could use .queryselector but it seems not. I cannot use the ID on the input.
var input = document.querySelectorAll('.pt-page.pt-subpage-current input');
var solve = input[0];
console.log(solve);
<div class="pt-page pt-subpage-current"> /*only identifier*/
<div class="container">
<div class="question">
<div class="input">
<input name="school" type="text" id="schoolCode1" autocomplete="off">/*target*/
</div>
</div>
</div>
</div>
I thought i could use query selector like above (I have been through many iterations) but no dice.
Upvotes: 0
Views: 989
Reputation: 1625
Use the direct descendant selector >
$('#mainDiv > p:first')
or even children()
$('#mainDiv').children('p').first()
Upvotes: 1