Javascript examples for Browser Object Model:Window getComputedStyle
Use getComputedStyle 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(){//from w ww . j a v a 2 s .c o 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>