Lets say, we have a div element with id as "divMessage" and on click of a button, we want to toggle display this element; we can write following code.
html code <div id="divMessage">My Message</div>
<input type="button" value="Toggle Display" id="btnShowHide" name="btnShowHide" onclick="ShowHide('divMessage')" />
javascript code <script language="JavaScript" type="text/javascript">
function ShowHide(id)
{
document.getElementById(id).style.display==''?document.getElementById(id).style.display='none':document.getElementById(id).style.display='';
}
</script>
When we shall click the Toggle DIsplay button, the div element will toggle display (if it will be hidden, it will be shown otherwise it will be hidden).