HKellner Posted April 28, 2020 Share Posted April 28, 2020 Hi, I used the W3S "how to create a dropdown", but that exercise only ever includes one button dropdowns and I want at least two side by side. I set up my page for this forum question: https://zandkantiques.com/test.html Please note the buttons show up on mobile devices only, so you have to be inspecting the page as a phone. Here is the code I'm using for the buttons: <!--mobile nav--> <div class="dropdown"> <button onclick="myFunction()" class="dropbtn">Fiesta Colors ▾</button> <div id="myDropdown" class="dropdown-content"> <a href="#" target="_blank">Red »</a> <a href="#" target="_blank">Yellow »</a> <a href="#" target="_blank">Blue »</a> <a href="#" target="_blank">Ivory »</a> <a href="#" target="_blank">Green »</a> <a href="#" target="_blank">Turquoise »</a> <a href="#">'50s Colors »</a> <a href="#" target="_blank">Medium Green »</a> </div> </div> <div class="dropdown"> <button onclick="myFunction()" class="dropbtn">Pottery Lines ▾</button> <div id="myDropdown" class="dropdown-content"> <a href="#" target="_blank">Fiesta Kitchen Kraft »</a> <a href="#" target="_blank">HLC Harlequin »</a> <a href="#" target="_blank">HLC Riviera »</a> <a href="#" target="_blank">HLC Decalware »</a> </div> </div> and the JS that was included from the lesson: <script type="application/javascript"> /* When the user clicks on the button, toggle between hiding and showing the dropdown content */ function myFunction() { document.getElementById("myDropdown").classList.toggle("show"); } // Close the dropdown if the user clicks outside of it window.onclick = function(event) { if (!event.target.matches('.dropbtn')) { var dropdowns = document.getElementsByClassName("dropdown-content"); var i; for (i = 0; i < dropdowns.length; i++) { var openDropdown = dropdowns; if (openDropdown.classList.contains('show')) { openDropdown.classList.remove('show'); } } }}</script> I don't think the css has anything to do with my problem, so am not including any css here. Thanks a zillion in advance!!!!!!! Link to comment Share on other sites More sharing options...
Recommended Posts