/    Sign up×
Community /Pin to ProfileBookmark

Changing styles with Javascript

I’m trying to cut down on the page space one of my link menus takes up, so I tried to write a code that would only display the itemized links if I click on the main one. I keep getting script errors, and would appreciate any help.

My test style:

[code=php]
#test {visibility: hidden; display: none;}
[/code]

My attempt at Javascript (just the open function to make it easier to read):

[code=php]
function openMenu(lookit) {
if((document.getElementById)&&(document.getElementById(lookit).style.visibility = “hidden”)) {
document.getElementById(lookit).style.visibility = “visible”;
document.getElementById(lookit).style.display = “block”;
}
elseif((document.all)&&(document.all[lookit].style.visibility = “hidden”)) {
document.all[lookit].style.visibility = “visible”;
document.all[lookit].style.display = “block”;
} }
[/code]

And lastly, the call to the function itself:

[code=php]
<li><a href=”javascript:openMenu(‘test’);”>Test</a></li>
<div id=”test”><ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul></div>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@WildcatauthorJan 28.2004 — Er, ignore the image tag in the last part. I think that happened when I was previewing the code. it's supposed to read openMenu
×

Success!

Help @Wildcat 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.19,
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,
)...