The cssText property sets or gets the value of an element's inline style declaration.
Return the value of the inline style of a H1 element:
Click the button to return the value of the element's inline style declaration.
<!DOCTYPE html> <html> <body> <h1 style="color: red; font-size:50px;">The cssText Property</h1> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w w w. jav a 2 s . c o m*/ var elmnt = document.getElementsByTagName("h1")[0]; var x = elmnt.style.cssText; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The cssText property returns a String representing the inline style of the specified element.