Today, when it comes to encapsulating a library , I find that I want to get the CSS property of the node, if we don't write the style of the line, but write it through link, we want to pass the. Style. property in JavaScript , which is not available.
Looked up on the internet, The Web provides a method:window.getComputedStyle () can get the calculation of the node's style, the method has two parameters, the first is to get the style of the node, The second parameter does not know what the effect is, and the example given on the web will be set to NULL, that is, a collection of property value pairs that are called window.getComputedStyle (Node,null), whose return value is an object, for the computed style.
However, the method is not supported in IE , but in IE, the element node has a property corresponding to the method that the node calculates, for example, in IE, the node is computed in the following style:Node.currentstyle, This property is a collection of property value pairs that are an object and also a computed style. For compatibility we can rewrite its package to provide a unified approach to Getcurrentstyle (node)
To show an example:
argument node: The element node that will get its calculated style, function Getcurrentstyle (node) { nullifnull);} else{style =return style;}
The following code is the Style property value that gets the display of the DIV:
1 <div id= "div" >div node </div> 4 <script>var div = document.getElementById ("div"); var style = Getcurrentstyle (div); var display = style["display"]; output: Block</script>
External reference CSS properties in JavaScript how to get