/    Sign up×
Community /Pin to ProfileBookmark

(Un)expand menus

Hey,

I found a script to expand/unexpand menus:

[code=php]
<script language=”JavaScript”>
<!–
function expandIt(getIt){
getIt.style.display=(getIt.style.display==”none”)?””:”none”;
}
//–>
</script>
<ul>
<li><a href=”javascript:expandIt(document.getElementById(‘listOne’))”>WebBuilder Sites</a>
<p id=”listOne” style=”display:none”>
<a href=”http://www.indiwiz.com/web/”>[url]www.indiwiz.com/web/[/url]</a><br/>
<a href=”http://www.builder.com/”>[url]www.builder.com[/url]</a><br/>
</p>
<li><a href=”javascript:expandIt(document.getElementById(‘listTwo’))”>Clipart Sites</a>
<p id=”listTwo” style=”display:none”>
<a href=”http://www.clipsahoy.com”>[url]www.clipsahoy.com[/url]</a><br/>
<a href=”http://www.abcgiant.com”>[url]www.abcgiant.com[/url]</a><br/>
</p>
</ul>
[/code]

But I want the one menu to close when the 1st one opens. Any suggestions? I’m new to javascript…

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorDec 07.2004 — Try

[code=php]
<script language="JavaScript" type="text/JavaScript">
var men = new Array()
men[0] = 'listOne';
men[1] = 'listTwo';
//you may add here the other menu's ids incrementing the array's index

function expandIt(getIt){
for(var i=0;i<men.length;i++){//collapse all
if(getIt!=document.getElementById(men[i])){
document.getElementById(men[i]).style.display='none')
}
}
getIt.style.display=(getIt.style.display=="none")?"":"none";
}
</script>
[/code]
Copy linkTweet thisAlerts:
@lux05authorDec 07.2004 — I tried your script but now they don't expand at all......?
Copy linkTweet thisAlerts:
@lux05authorDec 08.2004 — please don't forget me....
Copy linkTweet thisAlerts:
@KorDec 08.2004 — I have corrected some HTML errors either

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
var men = new Array()
men[0] = 'listOne';
men[1] = 'listTwo';
//you may add here the other menu's ids incrementing the array's index

function expandIt(q){
var getIt = document.getElementById(men[q]);
for(var i=0;i<men.length;i++){//collapse all
if(getIt!=document.getElementById(men[i])){
document.getElementById(men[i]).style.display='none';
}
}
getIt.style.display=getIt.style.display=="none"?"":"none";
}
</script>
</head>
<body>
<ul>
<li><a href="#" onclick="expandIt(0);return false">WebBuilder Sites</a>
<div id="listOne" style="display:none">
- <a href="http://www.indiwiz.com/web/"></a><a href="http://www.indiwiz.com/web/" target="_blank">www.indiwiz.com/web/</a><br/>
- <a href="http://www.builder.com/"></a><a href="http://www.builder.com" target="_blank">www.builder.com</a><br/>
</div>
<li><a href="#" onclick="expandIt(1);return false">Clipart Sites</a>
<div id="listTwo" style="display:none">
- <a href="http://www.clipsahoy.com"></a><a href="http://www.clipsahoy.com" target="_blank">www.clipsahoy.com</a><br/>
- <a href="http://www.abcgiant.com"></a><a href="http://www.abcgiant.com" target="_blank">www.abcgiant.com</a><br/>
</div>
</ul>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@lux05authorDec 08.2004 — Thanks, it now works ?
×

Success!

Help @lux05 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...