Manfred Kooistra wrote on 24 jan 2007 in comp.lang.javascript
:
Quote:
Thanks, Evertjan. I changed the file to this:
[please always quote on usenet]
Quote:
<html>
<head>
<script language="javascript" type="text/javascript">
//<![CDATA[
Why this CDATA stuff?? Leave it out!!!!!!!!!
Quote:
function mySwitch() {
document.getElementById('one').style.display = 'none';
document.getElementById('two').style.display = 'block';
>}
//]]>
</script>
</head>
<body>
<div id="one" style="display: block;">content</div>
<div id="two" style="display: none;">content</div>
<div><a href="#" onclick="mySwitch(); return false;">Switch</a></div>
<body>
</html>
>
There is no error message, it simply does nothing.
>
It would SHOW(!!!) nothing as "content" is the same as "content"!
Try this:
=========== test.html ================
<div id="one" style="display: block;">content: 1</div>
<div id="two" style="display: none;">content: 2</div>
<a href="#" onclick="mySwitch(); return false;">Switch</a>
<script type='text/javascript'>
function mySwitch() {
document.getElementById('one').style.display = 'none';
document.getElementById('two').style.display = 'block';
}
</script>
=======================================
You see you do NOT need any header for this testing,
at least in IE and FF.
Preferably, IMHO, use a button,
an anchor is for linking:
<button onclick='mySwitch();'>Switch</button>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)