Hello all,
My first thread here and im in need of some Javascript help. I have 3 categories: Starters, Mains and Sides, which when clicked displays any content inside my element. This is great but I would like to go that bit further and have only one element on show at any one time.
I thought it would be best to put the elements into an array but I have no idea where to go from here. Unfortunately Im not very literate with javascript which is a shame as it has alot of scope for some cool functionality.
My code so far:
<script type="text/javascript">
function showStuff(id) {
var switch_elements = new Array('starters', 'mains', 'sides');
if(document.getElementById(id).style.display == "none"){
document.getElementById(id).style.display = "block";
}else{
document.getElementById(id).style.display = "none";
}
}
function hideStuff(id) {
document.getElementById(id).style.display = 'none';
}
</script>
<p><a href="#" onclick="showStuff('starters'); return false;">Starters</a><br>
<span id="starters" style="display: none;">Starters</span></p>
<p><a href="#" onclick="showStuff('mains'); return false;">Main Dishes</a><br>
<span id="mains" style="display: none;">Main Dishes</span></p>
<p><a href="#" onclick="showStuff('sides'); return false;">Side Dishes</a><br>
<span id="sides" style="display: none;">Side Dishes</span></p>
Thanks in advance for any help with this! :)