/    Sign up×
Community /Pin to ProfileBookmark

Expanding and collapsing info with the (+) or (-) signs? help!

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 08.2003 — Just number everything correctly to add more headlines.
[code=php]
<!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>
[/code]
Copy linkTweet thisAlerts:
@McBeaverauthorSep 09.2003 — Thanks Fang, I appreciate it. I will give this a shot tonight!

-Eric
×

Success!

Help @McBeaver spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...