Hello, im preety new to JS but i've managed to create a function to show and hide a div according to a link's URL, but im gonna have lots of url's and lots of div's to show and hide, its not a problem to show and hide them, the only trouble is that they stack, if i show div 1, and then press link 2 to show div 2, Div 2 is gonna be below div 1, and what i want is that when i click link 2 to hide div 1 or any other shown divs, im sure its possible but i don't know how to do it.
I think it would be possible by storing the id of the div in a variable, but the only problem is that when i call that function, the variable always changes so it would be a matter of storing the id in a variable outside the function, but i don't know how to do that, or what are the rules and i really don't have much time to study deep into it, plz some help?.
This is my code:
JS
Code:
function showHide(product) {
var el = document.getElementById(product);
el.className = (el.className == 'hide') ? '' : 'hide';
}
HTML
Code:
<div id="1" class="hide">Content of Div 1</div>
<div id="2" class="hide">Content of Div 2</div>
<a href="javascript:showHide('1');">Show Hide 1</a>
<a href="javascript:showHide('2');">Show Hide 1</a>
CSS
Code:
.hide {
display:none;
}
NOTE = I need to have the javascript function call in href because of an applet im using.
In resume, the divs are hidden at the start, when i click one link, the div shows, when i click the other link i need the previous div shown to be hidden (class="hide"), and show the new div and so on.
Thank you for the help in advance!!