javascript - jscript dropdown menu doesn't work on other buttons -
im creating navigation bar using button dropmenu. 1 button functions (abou button). clicking other button (blog) displays same dropmenu though put different menu it. here's code. thank help.
javascript:
function myfunction(){ document.getelementbyid("mydropdown").classlist.toggle("show"); } window.onclick = function(event){ if(!event.target.matches('.dropbtn')){ var dropdowns = document.getelementsbyclassname("dropdown-content"); var i; for(i = 0; < dropdowns.length; i++){ var opendropdown = dropdowns[i]; if(opendropdown.classlist.contains('show')){ opendropdown.classlist.remove('show'); } } } }
html:
<div class="dropdown"> <button onclick="myfunction()" class="dropbtn"> <img src="images/whitearrow.png" width="10" height="10" ></button> <div id="mydropdown" class="dropdown-content"> <a href="site_profile.php">company profile</a> <a href="management.php">management</a> <a href="testimonials.php">testimonials</a> <a href="services.php">services </a> </div> </div> <div class="dropdown"> <span><button onclick="myfunction()" class="dropbtn" >blog <img src="images/whitearrow.png" width="10" height="10" ></button></span> <div id="mydropdown" class="dropdown-content"> <a href="#">tips</a> <a href="#">success story</a> <a href="#">featured employee</a> <a href="#">events </a> </div> </div>
Comments
Post a Comment