3

Some style parameters can be changed easily, such as:

document.getElementById(element).style.height = height + "px"; 

But how can I change those parameters that begin with -, such as -o-transform-origin ?

document.getElementById(element).style.-o-transform-origin = "top left"; // error!

Please advice, how to do with pure old-fashion JavaScript (no jQuery, no Dojo, ...).

1
  • 2
    Open the browser js console, then type that whole string up to style. you should get entire list of parameters in the autocomplete box, assuming a decent browser. Commented Jul 8, 2012 at 0:54

2 Answers 2

5

Use bracket notation:

document.getElementById(element).style['-o-transform-origin'] = "top left"
Sign up to request clarification or add additional context in comments.

Comments

4

The following link will shed some light:

http://www.javascriptkit.com/javatutors/setcss3properties.shtml

Also, I'll include some code from the link in case of link rot!

function getsupportedprop(proparray) {
    var root = document.documentElement //reference root element of document
    for (var i = 0; i < proparray.length; i++) { //loop through possible properties
        if (typeof root.style[proparray[i]] == "string") { //if the property value is a string (versus undefined)
            return proparray[i] //return that string
        }
    }
}

//SAMPLE USAGE
var boxshadowprop = getsupportedprop(['boxShadow', 'MozBoxShadow', 'WebkitBoxShadow']) //get appropriate CSS3 box-shadow property
document.getElementById("mydiv").style[boxshadowprop] = "5px 5px 1px #818181" //set CSS shadow for "mydiv"​​​​

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.