Javascript examples for DOM:Element style
The style property returns a CSSStyleDeclaration object, which represents an element's style attribute.
Return style properties:
Set style properties with the following Values
Value | Description |
---|---|
value | Sets the value of the specified property. |
A CSSStyleDeclaration object, representing an element's style attribute
The following code shows how to access the <style> element from <head> by using document.getElementsByTagName():
<!DOCTYPE html> <html> <head> <style> body {//from www .j av a 2s.c o m background-color: yellow; color: red; font-size: 15px; } </style> </head> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementsByTagName("STYLE")[0]; document.getElementById("demo").innerHTML = x.innerHTML; } </script> </body> </html>