Javascript examples for Browser Object Model:Window
The following code shows how to Get all the computed styles from an element:
<!DOCTYPE html> <html> <body> <p><button onclick="myFunction()">Test</button></p> <div id="test" style="height: 50px;background-color: lightblue;">Test Div</div> <p><span id="demo"></span></p> <script> function myFunction(){/* ww w.j ava 2 s . co m*/ var elem = document.getElementById("test"); var txt = ""; cssObj = window.getComputedStyle(elem, null) for (i = 0; i < cssObj.length; i++) { cssObjProp = cssObj.item(i) txt += cssObjProp + " = " + cssObj.getPropertyValue(cssObjProp) + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>