I'm trying to create a simple custom dropdown with absolute position in its container parent, and when the parent is clicked it has to show the dropdown. the problem is that when I click on the child its calling the click method of its parent.
click on the green area (the parent).
function clickHere() {
if (document.getElementById("drop").style.display == "block") {
document.getElementById("drop").style.display = "none";
} else {
document.getElementById("drop").style.display = "block";
}
}
<div style="background:red; height:500px;">
<div onclick="clickHere()" style="margin:auto;height: 40px; width:30%; background:green; position:relative;">
<div id="drop" style="display:none;width:100%; height:200px; background:blue; position:absolute; top: 100%; margin:0;">
<h3 style="text-align: center; color:white;">Hello</h3>
<h3 style="text-align: center; color:white;">Hello</h3>
<h3 style="text-align: center; color:white;">Hello</h3>
<h3 style="text-align: center; color:white;">Hello</h3>
</div>
</div>
</div>