cant get my dropdown list to close when I click outside the button the function above renders the dropdown button to work completly. The function at the bottom of the page is the on Im trying to get to work at the moment it renders the other function inside the script impossible to use, the work if I remove it. The dropwdown html thats in the code below is just an example.
//this is how the dropdown looks like got it from //http://www.w3schools.com/w3css/w3css_dropdowns.asp
<div class="w3-dropdown-click">
<button onclick="myFunction()" class="w3-btn">ClickMe</button>
<div id="Demo" class="w3-dropdown-content w3-card">
/*some example links*/
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
// I use two of these on my page
<script>
//this functions open and closes my dropdown when clicked
function myFunction(event) {
//opens the selected dropdownlist
document.getElementById("Demo").classList.toggle("w3-show");
//closes the other dropdownlist
document.getElementById("Demo2").classList.remove("w3-show");
event.stopPropagation();
}
//this functions open and closes my other dropdown when clicked
function myFunction2(event) {
//opens the selected dropdownlist
document.getElementById("Demo2").classList.toggle("w3-show");
//closes the other dropdownlist
document.getElementById("Demo").classList.remove("w3-show");
event.stopPropagation();
}
// the funtion im trying to get to work it should close the dropdown when Im clicking outsid of the dropdown buttons
$(":not(#Demo2)").click( function(){
document.getElementById("Demo").classList.remove("w3-show");
document.getElementById("Demo2").classList.remove("w3-show");
});
</script>