2

So for example I can do this:

document.getElementById('element').onclick = function() {
    document.getElementById('element').style.color = '#FFFFFF';
}

But how should I do this?

document.getElementById('element').onclick = function() {
    document.getElementById('element').style.-moz-box-shadow = '1px 1px 1px #000'; 

}

I hope you get what I mean :)

Please do not post any answer related with jQuery or any library, I want it in plain javascript.

2
  • Why are you trying to edit the style directly, rather than modify classes? You're just building in brittle browser awareness. Commented Aug 24, 2010 at 13:07
  • -moz-box-shadow has nothing to do with CSS3. See the vendor-specific prefix? That means it's non-standard. Commented Aug 24, 2010 at 14:13

2 Answers 2

5

I believe it's:

myobject.MozBoxShadow = '1px 1px 1px #000';

It doesn't follow the "typical" formatting of a style object (which would lower-case the "M") because of the initial "-" character. Converting between style properties and JS properties for those styles means:

  1. Converting the first character to lower case
  2. Converting all characters after dashes to upper case
  3. Removing all dashes

Thus, "-moz-box-shadow" becomes:

  1. -moz-box-shadow (the first character is a "-", so it doesn't have a lower case)
  2. -Moz-Box-Shadow
  3. MozBoxShadow
Sign up to request clarification or add additional context in comments.

1 Comment

Yes it is :D I've found it just right now somewhere, thanks for your answer ;)
1

I think you change '-' to a capital letter, so:

 document.getElementById('element').style.-moz-box-shadow = 1px 1px 1px #000;

Should be:

  document.getElementById('element').style.MozBoxShadow = "1px 1px 1px #000";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.