My task involves a parent div containing a centered child div. My goal is to have the child div grow downwards only upon clicking it, not in both directions.
Initial state of the two divs:
https://i.sstatic.net/cWYyV.png
Outcome after clicking on div 2:
https://i.sstatic.net/QGSDJ.png
Desired result after clicking on div 2:
https://i.sstatic.net/iossE.png
let div2 = document.querySelector("#div2");
div2.addEventListener("click", e => {
div2.style.height = "300px";
})
#div1 {
height: 200px;
width: 200px;
outline: red solid medium;
display: flex;
justify-content: center;
align-items: center;
}
#div2 {
height: 100px;
width: 100px;
outline: blue solid medium;
}
<div id="div1">
<div id="div2"></div>
</div>