I'm struggling with changing the color of a div when clicked while preventing its parent's pseudo-class from triggering. Here is the markup I have:
<div class="parent">
I should change my color to green when clicked
<div class="element">I should do nothing when clicked</div>
</div>
Below is the corresponding CSS:
.parent {
width:200px;
height:200px;
background: red;
color: #fff;
}
.parent:active {
background:green;
}
.element {
background:blue;
}
I have tried using e.stopPropogation()
when .element
is clicked, but it didn't work. Any suggestions on how to achieve this? Check out the demo.