How can I display a div if a parent div has a specific class using JS?
In the code below I would like to display the div with class .hidden-gray only if parent div below has class .matched and child div has class .gray.
And, the div with class .hidden-purple only if parent below div has class .matched and child div has class .purple.
<div class="hidden-gray">
Display this div only if parent div has class .matched AND child div has class .gray
</div>
<div class="hidden-purple">
Display this div only if parent div has class .matched AND child div has class .purple
</div>
<div class="turn matched" id="1">
<div class="tile gray">
<div class="face front" style="background-color: transparent;">
<img src="https://via.placeholder.com/336x221">
</div>
</div>
</div>
<div class="turn matched" id="2">
<div class="tile purple">
<div class="face front" style="background-color: transparent;">
<img src="https://via.placeholder.com/336x221">
</div>
</div>
</div>
CSS
.mystyle {
width: 100%;
padding: 25px;
background-color: coral;
color: white;
font-size: 25px;
box-sizing: border-box;
}
.turn {
margin-top: 10px;
}
.hidden-gray {
padding: 20px;
background-color: gray;
color: white;
margin-bottom: 10px;
}
.hidden-purple {
padding: 20px;
background-color: purple;
color: white;
margin-bottom: 10px;
}
Many thanks!
.hidden-purple?