Click to See Complete Forum and Search --> : Expanding and collapsing info with the (+) or (-) signs? help!


McBeaver
09-07-2003, 11:41 PM
Hello-

I have been trying to do this specific functionality with no luck. I have a bunch of headlines that have (+) signs next to them. When the (+) is clicked, It expands a bit of text below it, changing the (+) to a (-). Clicking the (-) collapses the headline. This is something I have seen before, but am having trouble doing myself. If someone could point me towards a tutorial or a bit of code to clue me in, Id appreciate it greatly. Thanks!

-Eric

Fang
09-08-2003, 03:00 AM
Just number everything correctly to add more headlines.

<!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" xml:lang="en" lang="en">
<head>
<title>headline</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<script type="text/javascript">
//<![CDATA[
<!--
function Toggle(num) {
var obj=document.getElementById('info'+num);
var sign=document.getElementById('span'+num)
if(obj.className=='expanded') {
obj.className='collapsed';
sign.innerHTML='+';
}
else {
obj.className='expanded';
sign.innerHTML='-';
}
}
//-->
//]]>
</script>
<style type="text/css">
<!--
span.sign {
cursor:pointer;
color:blue;
}
.expanded {display:block;}
.collapsed {display:none;}
-->
</style>
</head>
<body>
<div id="div1">Headline <span onclick="Toggle(1);" id="span1" class="sign">+</span></div>
<div id="info1" class="collapsed">more information</div>
</body>
</html>

McBeaver
09-09-2003, 08:48 AM
Thanks Fang, I appreciate it. I will give this a shot tonight!

-Eric