I am working with 3 divs at the moment – on pageLoad the default is viewed but when the user clicks on a button the div is hidden and the selected div appears in its place.
How would I write an if statement to identify the div currently selected by the user? For example:
if selected_div is 'dpara' then ....
else if selected_div is dtab then ....
Thanks in advance!
<script type='text/javascript'>
function arrange(div_id) {
// First make all the divs hidden...
divs = document.getElementsByTagName('div');
for( var i = 0; i < divs.length; i++ ) {
divs[i].style.display = 'none';
}
// Now make the one we want to be visible visible...
document.getElementById(div_id).style.display = 'block';
}
</script>
<form>
<input type='button' value='dpara' onclick='arrange(this.value);' />
<input type='button' value='dtab' onclick='arrange(this.value);' />
<input type='button' value='ddl' onclick='arrange(this.value);' />
</form>
<div id='dpara'>
</div>
<div id='dtab' style='display: none'>
</div>
<div id='ddl' style='display: none'>
</div>
As you’re already going through a function for each button click you could just keep the visible
divin a variable, something like: