Claudius Posted January 8, 2020 Share Posted January 8, 2020 The Navigation Bar with Dropdown uses a script to open one dropdown with one id. I need more different dropdowns but don't know how to let getElementById("demo")open more id's. The construction getElementById("demo1", "demo2") doesn't work. Neither does the construction getElementByClass. Please help. <script> function myFunction() { var x = document.getElementById("demo"); if (x.className.indexOf("w3-show") == -1) { x.className += " w3-show"; } else { x.className = x.className.replace(" w3-show", ""); } } </script> Link to comment Share on other sites More sharing options...
dsonesuk Posted January 8, 2020 Share Posted January 8, 2020 (edited) If the element that calls the function is the element with the id ref name use onclick="myFunction(this)" to add argument 'this' (no quotes) Then change function to function myFunction(elem) { var x = document.getElementById(elem.id); if (x.className.indexOf("w3-show") == -1) { x.className += " w3-show"; } else { x.className = x.className.replace(" w3-show", ""); } } Edited January 8, 2020 by dsonesuk Link to comment Share on other sites More sharing options...
Claudius Posted January 8, 2020 Author Share Posted January 8, 2020 It works. Thank you very mnuch. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now