4

I am curious how one would access/modify properties like -moz-transition (or any property from this list) by means of native javascript i.e. without relying on jQuery's .css('property', 'value');

For instance, to change an element's background-color one would work with element.style.backgroundColor.

Do vendor-specific property names just get camelCased and become operable? I couldn't do so, maybe they are no longer represented by properties of style and should be modified elsewhere? Or maybe they are not accessible through DOM at all?

2 Answers 2

3

Use upper camel case, e.g., el.style.MozTransition.

Example: http://jsfiddle.net/R3y6f/1/

Sign up to request clarification or add additional context in comments.

2 Comments

Amazing! I was camel-casing it as mozTransition instead, was there some documentation that pointed you to capitalizing the first letter of the property? I never could find any
Be aware that Microsoft does it differently.
2

ex: -webkit-box-shadow

.style.setProperty("-webkit-box-shadow", "0 0 7px #ccc", null);
.style.removeProperty("-webkit-box-shadow");
.style["-webkit-box-shadow"];

3 Comments

Does this imply that they are not accessible as DOM element properties?
they are style properties, not element properties ;)
I get lost in semantics thinking of style being a complex element property, kind of confirmed by .style['property'] notation. Which is pretty neat, TIL, +1!

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.