title: javascript conflict when using code 3 times
body: <p>How do i get this code to work 3 times, one for my desktop version, one for my tablet and one for my desktop version. I want it to exit the menu when clicking on the window/document. Keep in mind that iam new in javascript... The code only seem to work one time. See my not complete webpage, www.adamlee.se</p>
  
  <pre><code>    &lt;script&gt;
  /* When the user clicks on the button, 
  toggle between hiding and showing the dropdown content */
  function desktopmyFunction() {
  document.getElementById("desktopmyDropdown").classList.toggle("show");
  }
  
  // Close the dropdown if the user clicks outside of it
  window.onclick2 = function(event) {
  if (!event.target.matches('.desktop-dropbtn')) {
  
  var dropdowns = document.getElementsByClassName("desktop-dropdown-content");
  var i;
  for (i = 0; i &lt; dropdowns.length; i++) {
    var openDropdown = dropdowns[i];
    if (openDropdown.classList.contains('show')) {
      openDropdown.classList.remove('show');
    }
  }
  }
  }
  &lt;/script&gt;
  </code></pre>