Get the owner Node of the style sheet

Description

The following code shows how to get Basic Information About Stylesheets.

Example


<!DOCTYPE HTML>
<html>
<head>
<style title="core styles">
p {<!--from  w ww.j  a v a 2s .c  o  m-->
  border: medium double black;
  background-color: lightgray;
}

#block1 {
  color: white;
}
</style>
<link rel="stylesheet" type="text/css" href="styles.css" />
<style media="screen AND (min-width:500px)" type="text/css">
#block2 {
  color: yellow;
  font-style: italic
}
</style>
</head>
<body>
  <p id="block1">This is a test.</p>
  <p id="block2">This is a test.</p>
  <div id="placeholder" />
  <script>
    var placeholder = document.getElementById("placeholder");
    var sheets = document.styleSheets;
    for (var i = 0; i < sheets.length; i++) {
      var newElem = document.createElement("table");
      newElem.setAttribute("border", "1");
      newElem.innerHTML += "<tr><td>index:</td><td>" + i + "</td></tr>";
      newElem.innerHTML += "<tr><td>ownerNode:</td><td>" + sheets[i].ownerNode.tagName + "</td></tr>";
      placeholder.appendChild(newElem);
    }
    function addRow(elem, header, value) {
    }
  </script>
</body>
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window