I'm trying to make a dropdown menu just by changing <div's>
with Js.
Is there any way to use only function()
to change <div's>
?
The only solution I found is to create a function()
for each <div>
that I want to hide / unhide but it would be too long the code.
What I've achieved so far is to hide and unhide a single <div>
.
Following:
JavaScript:
function startmenu(){
ex1.style.display = "none";
}
function abrefecha(){
if(ex1.style.display == "none")
{
ex1.style.display = "block";
}
else
{
startmenu();
}
}
HTML:
<body>
<h1>Exercícios JavaScript</h1>
<a href="javaScript:abrefecha()"><h2> Exercício 1 </h2></a>
<div id="ex1" style="display: none;">
</div>
<a href="javaScript:abrefecha()"><h2> Exercício 2 </h2></a>
<div id="ex2" style="display: none;">
</div>
<a href="javaScript:abrefecha()"><h2> Exercício 3 </h2></a>
<div id="ex3" style="display: none;">
</div>
...