/    Sign up×
Community /Pin to ProfileBookmark

1 second it works, next second it doesn’t

Hey,
I’ve just started using Javascript after a few years of not using it and I’m encountering problems already.
Ok, first I had this function:

[CODE]function gotousermenu() {
document.getElementById(‘mainmenu’).style.display=”none”;
document.getElementById(‘usermenu’).style.display=”block”;
}[/CODE]

That worked fine.
But then I changed it to this:

[CODE]function gotousermenu() {
document.getElementById(‘menutab’).style.background-color=”#7db7ff”;
document.getElementById(‘usertab’).style.background-color=”#5591db”;
document.getElementById(‘mainmenu’).style.display=”none”;
document.getElementById(‘usermenu’).style.display=”block”;
}[/CODE]

And it doesn’t work. menutab and usertab are A tags. mainmenu and usermenu are DIV tags.
Why doesn’t it work when I do that. Even the bit that worked originally doesn’t work with that extra code.
Thanks for helping.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 07.2005 — Hyphenated properties loose the hyphen and change the following letter to capital:<i>
</i>document.getElementById('menutab').style.backgroundColor="#7db7ff";
Copy linkTweet thisAlerts:
@saulssOct 07.2005 — from what i can see, everything looks fine, maybe you should put the rest of the code because the error might be there

EDIT: oops nvm...
Copy linkTweet thisAlerts:
@UltimaterOct 07.2005 — Something to run in order to understand why JavaScript had to use backgroundColor instead of background-color and to help remember the difference between the two:
<i>
</i>&lt;body&gt;
&lt;p&gt;
&lt;input type="text" id="el" value="val" style="background: rgb(125, 183, 255) none repeat scroll 0% 0%;"&gt;&lt;script type="text/javascript"&gt;
var color=2
alert(7-color)
alert("7"-color)
alert("#7db7ff"-color)
alert(document.getElementById("el").style.background)
alert(document.getElementById("el").style.background-color)
alert(document.getElementById("el").style.backgroundColor)
&lt;/script&gt;
&lt;/body&gt;
Copy linkTweet thisAlerts:
@saulssOct 07.2005 — oh niceeee thanks for the example
×

Success!

Help @sftrprod 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.16,
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,
)...