Рассмотрим CSS -Сеть, примененную к body
function thefunc() {
document.querySelector('body').classList.add('overlap');
}
#div1 {
display: inline-block;
background: red;
opacity: .5;
}
#div2 {
display: inline-block;
background: blue;
}
div[id] {
width: 200px;
height: 200px;
}
.overlap {
display: grid
}
.overlap div {
grid-row: 1;
grid-column: 1;
}
#div1 {
z-index: 2;
}
<div id='div1' onClick="thefunc()"></div>
<div id='div2'></div>