javascript - Problems with multiple dropdown menus -


i'm experimenting multiple dropdown menus. works problem third button closes when click on else third button doesnt work 2 other buttons,

sidenote: when removed 3rd button second button work.

here code. know way make work 3 buttons.

<!doctype html>  <html>  <head>  <link rel="stylesheet" href="neww.css" type="text/css">    </style>  </head>  <body>    <ul>    <li class="logo"><a href="new2.html" id="img"><img class="logos" src="logo.png" alt="hitachi logo"></a></li><br>    <li><a href="#news">news</a></li><br>        <li class="dropdown">      <button onclick="myfunction()" class="dropbtn">dropdown</button>      <div id="mydropdown" class="dropdown-content">        <iframe name="inlineframe1" id="inlineframe1" allowtransparency="false" style=";" src="http://logistics.hds.com/"></iframe>      </div>    </li><br>    <script src="javascript.js"></script>         <li class="dropdown2">      <button onclick="myfunction1()" class="dropbtn2">dropdown</button>      <div id="mydropdown2" class="dropdown-content2">        <iframe name="inlineframe1" id="inlineframe2" style=";" src="http://www.nu.nl/"></iframe>      </div>    </li><br>        <li class="dropdown3">      <button onclick="myfunction2()" class="dropbtn3">dropdown3</button>      <div id="mydropdown3" class="dropdown-content3">        <iframe name="inlineframe1" id="inlineframe3" style=";" src="http://homt.hds.com/"></iframe>      </div>    </li><br>    <script src="javascript.js"></script>             </ul>    </body>  </html>

/* when user clicks on button,  toggle between hiding , showing dropdown content */  function myfunction() {      document.getelementbyid("mydropdown").classlist.toggle("show");  }    // close dropdown if user clicks outside of  window.onclick = function(event) {    if (!event.target.matches('.dropbtn')) {        var dropdowns = document.getelementsbyclassname("dropdown-content");      var i;      (i = 0; < dropdowns.length; i++) {        var opendropdown = dropdowns[i];        if (opendropdown.classlist.contains('show')) {          opendropdown.classlist.remove('show');        }      }    }  }  /* when user clicks on button,  toggle between hiding , showing dropdown content */  function myfunction1() {      document.getelementbyid("mydropdown2").classlist.toggle("show2");  }    // close dropdown if user clicks outside of  window.onclick = function(event) {    if (!event.target.matches('.dropbtn2')) {        var dropdowns2 = document.getelementsbyclassname("dropdown-content2");      var i;      (i = 0; < dropdowns2.length; i++) {        var opendropdown2 = dropdowns2[i];        if (opendropdown2.classlist.contains('show2')) {          opendropdown2.classlist.remove('show2');        }      }    }  }  /* when user clicks on button,  toggle between hiding , showing dropdown content */  function myfunction2() {      document.getelementbyid("mydropdown3").classlist.toggle("show3");  }    // close dropdown if user clicks outside of  window.onclick = function(event) {    if (!event.target.matches('.dropbtn3')) {        var dropdowns3 = document.getelementsbyclassname("dropdown-content3");      var i;      (i = 0; < dropdowns3.length; i++) {        var opendropdown3 = dropdowns3[i];        if (opendropdown3.classlist.contains('show3')) {          opendropdown3.classlist.remove('show3');        }      }    }  }


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -