I have code that uses a javascript loop to generate nested divs with various classes. I'm having trouble selecting the nth-child of a certain class amongs those nested divs. After the javascript runs, my html should look like this.
.twoN:nth-of-type(1) {
background-color: orange;
}
.twoN:nth-child(2){
background-color:orange;
}
<div id="grid">
<div style="width:50px; height:50px; color: white; background-color:blue" class="item oneN">1</div>
<div style="width:50px; height:50px; color: white; background-color:red" class="item twoN">1</div>
<div style="width:50px; height:50px; color: white; background-color:green" class="item twoN">1</div>
<div style="width:50px; height:50px; color: white; background-color:purple" class="item threeN">1</div>
</div>
I'm trying to select the first or second div with the class "twoN". But for some reason I can only get the Nth-Of-Type selector to work if I use the n variable e.g. nth-of-type(2n+1), but it won't work if I want to select the first child by doing something like nth-of-type(1). I also tried straight up nth-child(1) and that doesn't seem to work neither. I think I'm making some sort of hierarchy mistake.