How can I use query selector to exclusively target the p
and p2
divs inside of a r
class, without selecting them if they are outside of that class?
<div>
<div class="r"><div class="p"></div><div class="p2"></div></div> //This is what I want to select, using the parent div tag name
</div>
<div class="r"><div class="p"></div><div class="p2"></div></div> //I don't want to select this if the parent div is body
CSS
.p,.p2{
height:50px;
width:50px;
background-color:orange
}
I have tried the following JavaScript code. Is it correct for achieving this?
c = document.querySelectorAll(' x >.r' ) //where x is the parent tag tagName of r