Javascript DOM CSS Style object get from head section

Introduction

The Style object represents an individual style statement.

Access a Style Object

The Style object can be accessed from the head section of the document, or from specific HTML element(s).

Accessing style object(s) from the head section of the document:

var x = document.getElementsByTagName("STYLE");

Click the button to display the style properties of this document.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {//from   www  .j  a  v a 2 s. c om
  background-color: yellow;
  color: red;
}
</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>



PreviousNext

Related