Using Javascript and div tag to hide / unhide text

The javascript is called from an html anchor tag. The function accepts two argument. The first argument is the name of the anchor tag. This is so we can determine the state of hide/unhide and set an approriate label for the anchor. The second argument is the name of the div tag.

function eToggle(anctag,darg)

Javascript in Action


Show Help


Javascript Code

Javascript and html code are self contained below.

 
     
<head>
<meta http-equiv="Content-Type" content="text/html; 
    charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript"> 
function eToggle(anctag,darg) 
{
  var ele = document.getElementById(darg);
  var text = document.getElementById(anctag);
  if(ele.style.display == "block") 
  {
    ele.style.display = "none";
	text.innerHTML = "Show Help";
  }
  else 
  {
	ele.style.display = "block";
	text.innerHTML = "Hide Help";
  }
} 
</script>
</head>

<body>
<h1>Hide/Unhide a Div Tag</h1>
<h2>Javascript in Action
  <h2>
</h2>
<hr />
<p><a href="javascript:eToggle('atag','helptxt');" 
    id="atag">Show Help</a>
<p>
<div id="helptxt" style="display: none">
  <h3>div content goes here</h3>
</div>
<hr />
</body>
</html>
 

If you find this site useful and are a book buyer/reader...

Abe Books is one of my affiliates. I only use affiliates that I also purchase products from. I love Abe books. I have purchased many books from them originally cost $40 to $60 for as little as $5 to $10 dollars including shipping costs.

By accessing Abe books and clicking on one of my links I receive a small commission on your purchase that helps pay for this site. You pay no more for your books than if you accessed their site directly. Thanks for your support.

I have found Javascript - The Good Parts to be an indespensible resource

Click on the book to find books on Javascript at Abe Books...

If you would like a new version of the book click below to buy it from Amazon (also one of my affiliates).

Javascript Examples

Basics

Forms

Misc













navTango.com free

75% of your donation

goes to charity.