2 replies [Last post]
paCkeTroUTer
paCkeTroUTer's picture
Offline
Enthusiast
Melbourne, Australia
Last seen: 49 weeks 1 day ago
Melbourne, Australia
Timezone: GMT+10
Joined: 2003-06-27
Posts: 241
Points: 2

How can I change styles(background color) via javascript. Example:

document.getElementById("question"+errorQuestions[i]).style.background-color="#CCCC00";

I am trying to change the background color of a div on a questionnaire form, when the user has not answered a particular question. Above example doesn't work for some reason. Sad

http//melbourne.ug.php.net

Tags:
Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 hours 43 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5054
Points: 2632

Changing style(background color) via javascript

Hi paCkeTroUTer,
Your pretty close Smile the JavaScript style properties are slightly different to the CSS style properties.
Mostly for the JavaScript version you use lowercase first word and upper case first letter of second word with no space or hyphen.

So background-color becomes backgroundColor.

Hope that helps.

paCkeTroUTer
paCkeTroUTer's picture
Offline
Enthusiast
Melbourne, Australia
Last seen: 49 weeks 1 day ago
Melbourne, Australia
Timezone: GMT+10
Joined: 2003-06-27
Posts: 241
Points: 2

Changing style(background color) via javascript

Thanks Tony, that works. Didn't know about the syntax of javascript. Do you know of a resource that has a complete manual on JavaScript for me to refer to ?

http//melbourne.ug.php.net