How to write a JavaScript function to toggle display an html element?

Posted by Raja under JavaScript category on | Views : 5445
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)

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).

Comments or Responses

Login to post response