Hi,
I believe m^e's code won't work, since he forgot to include the script for the toggleview() function code. It is also a bit too complicated for what you want. Oh and all the document.write things have to be in one line, otherwise you'll get an "unterminated string literal" error.
Let's do this extensively ^^
To hide an HTML element, you just have to include the attribute style with no-display.
CODE
<div style="display:none">
This means that the <div> is not there at all. If you want to make it invisible, but keep the space as placeholder, then you would use "visibility: hidden" instead of "display: none".
Since some browsers do not support Javascript/users turned it off, the field should be shown by default. If you don't care about those without JS, then hide the div by default.
CODE
<div><script type="text/javascript"><!--
document.write("<div style='display:block' id='moreinfo'>");
//-->
</script>More Info, shown for those without Javascript<script type="text/javascript"><!--
document.write("</div>");
//--></script></div>
This way, the div will be shown to the users which have JS disabled, but it will be directly hidden from the ones with document.write-supporting browsers (nearly all). It's a lot of action for those few users without Javascript, but you should not neglect them. If you intend to do so, then do it directly.
CODE
<div style="display:none" id="moreinfo">More Info, shown for those without Javascript</div>
like this.
But from now on, the code for the JS-browsersNow, let's show this div :-)
you need only one simple JS-command for this purpose..
CODE
document.getElementById('moreinfo').style.display = 'none';
You can call this function with the onclick-eventhandler on any element, that you can click (almost all)
CODE
<a href="#" onclick="document.getElementById('moreinfo').style.display = 'block';">Show me what you got</a>
So, in the end your document would look something like this...
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Untitled Page</title>
</head>
<body>
<p><a href="#" onclick="document.getElementById('moreinfo').style.display = 'block';">Show me what you got</a></p>
<div><script type="text/javascript"><!--
document.write("<div style='display:none' id='moreinfo'>");
//-->
</script>More Info, shown for those without Javascript<script type="text/javascript"><!--
document.write("</div>");
//--></script></div>
</body>
</html>
works a 100%, I tried it out.
Good luck, feel free to ask back!
Comment/Reply (w/o sign-up)