My project involves creating a mobile website with a simple interaction where clicking on a div opens another div underneath it. The HTML structure consists of two stacked divs, with the CSS for the bottom div initially set to 'none'. Using JavaScript, an event listener is triggered by a click on the top div, changing the display property of the bottom div to 'block' and revealing it. How can I modify the code so that clicking on the top div again will hide the bottom div by setting its display back to 'none'?
Here is the current basic code snippet:
document.getElementById('divOne').addEventListener('click',function(){
document.getElementById('divTwo').style.display = 'block';
});
#divOne {
border: 1px solid black;
}
#divTwo {
border: 1px solid black;
display: none;
}
<div id="divOne">Click me</div>
<div id="divTwo">Hello World!</div>