silent11
05-17-2005, 03:24 PM
I am trying to get some content to appear/hide when I click on a link. I also want all of these divs to be hidden when the page loads. I can do this by ading hide_all(2) in the onLoad handler for the body tag. Well, since I'm working inside of a template I have no control over the body tag.
The code below "should" work (or atleast I think) but it's not.
any help would be GREATLY appreciated.
<html>
<head>
<title>toggle</title>
<script type="text/javascript">
<!--
function hide_all(many){
for (i=1; i <= many; i++) {
target_id = 'outside' + i;
alert(target_id);
document.getElementById(target_id).style.display = "none";
}
}
function toggle( targetId ){
if (document.getElementById){
target = document.getElementById( targetId );
if (target.style.display == "none"){
target.style.display = "";
} else {
target.style.display = "none";
}
}
}
hide_all(2);
-->
</script>
</head>
<body>
<h3>Blogs I Read <a href="#" onclick="toggle('outside1');return false;" title="Toggle BlogRoll">(show/hide)</a></h3>
<div id="outside1">
<a href="http://www.blog.com/">my blog</a><br />
<a href="http://www.perl.com">perl.com</a>
</div>
<h3>Search Engines <a href="#" onclick="toggle('outside2');return false;" title="Toggle BlogRoll">(show/hide)</a></h3>
<div id="outside2">
<a href="http://www.google.com">Google Search</a><br />
</div>
</body>
</html>
The code below "should" work (or atleast I think) but it's not.
any help would be GREATLY appreciated.
<html>
<head>
<title>toggle</title>
<script type="text/javascript">
<!--
function hide_all(many){
for (i=1; i <= many; i++) {
target_id = 'outside' + i;
alert(target_id);
document.getElementById(target_id).style.display = "none";
}
}
function toggle( targetId ){
if (document.getElementById){
target = document.getElementById( targetId );
if (target.style.display == "none"){
target.style.display = "";
} else {
target.style.display = "none";
}
}
}
hide_all(2);
-->
</script>
</head>
<body>
<h3>Blogs I Read <a href="#" onclick="toggle('outside1');return false;" title="Toggle BlogRoll">(show/hide)</a></h3>
<div id="outside1">
<a href="http://www.blog.com/">my blog</a><br />
<a href="http://www.perl.com">perl.com</a>
</div>
<h3>Search Engines <a href="#" onclick="toggle('outside2');return false;" title="Toggle BlogRoll">(show/hide)</a></h3>
<div id="outside2">
<a href="http://www.google.com">Google Search</a><br />
</div>
</body>
</html>