JSFiddle - React, Tailwind, and code Playground

by Kondal Durgam

HTML

<div id="parent">
  <div id="child">
        <div id="overLay"></div>
  </div>
</div>
<button href="#" id="x">Link 1</button>

CSS

#parent{
   background-color: blue;
    height: 250px;
    padding-top: 20px;
}
#child{
  background-color: pink;
    height: 100px;
    width: 80%;
}
#overLay{
    display:none;
    position: fixed;
    width: 100%;
    height: 100%;
    background-color: #707070;
    opacity: 0.7;
    z-index: 9;
    left: 0;
    top: 0;
}

JavaScript

var body = document.getElementById('parent');
var el = document.getElementById('child');

/* body.addEventListener("click", function () {
    alert("parent");
}, false); */
el.addEventListener("click", function (ev) {
    alert("child");
    ev.stopPropagation();
}, false);
document.getElementById("x").onclick = function () {
    overlay.style.display = "block";
};