Toggling Element
17
May
2013

JavaScript Code

<script language="JavaScript" type="text/JavaScript">
<!--
function toggle(id, id2 ) {

var toggle_block = document.getElementById(id);
var toggle_text = document.getElementById(id2);

if(toggle_block.style.display == 'block'){
toggle_block.style.display = 'none';
toggle_text.innerHTML = 'Expand';
}else{
toggle_block.style.display = 'block';
toggle_text.innerHTML = 'Hide';
}
}
//-->
</script>

HTML Code

<a href="#" id="toggleSwitch" onclick="toggle('comments', 'toggleSwitch');">Expand</a> Comments
<br>
<div id="comments" style="display:none; padding: 10px;">Now you see the comments</div>
  • 586 View
  • Pin It