I would like to create simple dropdown her is html code
<ul class="flex">
<li class="mr-10"><a href="#">Úvod</a></li>
<li onclick="dropdown1()" class="flex mr-14 cursor-pointer">Pekné vecičky
<div id="myDropdown1" class="dropdown-content hidden ">
<a href="#">Dropdown 1</a>
<a href="#">Dropdown 2</a>
<a href="#">Dropdown 3</a>
</div>
</li>
<li onclick="dropdown2() class="flex mr-14 cursor-pointer">Výprodej/Akce
<div id="myDropdown2" class="dropdown-content hidden ">
<a href="#">Dropdown 1</a>
<a href="#">Dropdown 2</a>
<a href="#">Dropdown 3</a>
</div>
</li>
<li onclick="dropdown3() class="flex mr-14 cursor-pointer">Šikovní ľudia
<div id="myDropdown3" class="dropdown-content hidden ">
<a href="#">Dropdown 1</a>
<a href="#">Dropdown 2</a>
<a href="#">Dropdown 3</a>
</div>
</li>
</ul>
my js looks like this
function dropdown1() {
document.getElementById("myDropdown1").classList.toggle("show-dropdown");
}
function dropdown2() {
document.getElementById("myDropdown2").classList.toggle("show-dropdown");
}
function dropdown3() {
document.getElementById("myDropdown3").classList.toggle("show-dropdown");
}
I am using tailwind hidden class and than on click I show element, it works fine but the question is how I can write this js function easier and don´t repeat the code?