Javascript DOM HTML CSSStyleDeclaration parentRule Property

Introduction

Return the CSS declaration and the CSS selector:

The parentRule property returns a CSSRule Object for the specified style declaration.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
h1 {/*w  w w  .ja  va  2s . co  m*/
  color: red;
  font-size: 50px;
}
</style>

<script>
function myFunction() {
  var s = document.styleSheets[0].rules[0].style;
  var ruleObj = s.parentRule;
  document.getElementById("demo").innerHTML = ruleObj.cssText;
}
</script>
</head>
<body>

<h1>The parentRule Property</h1>
<button onclick="myFunction()">Display the CSS Rule</button>

<p id="demo"></p>

</body>
</html>

The parentRule property returns a CSSRule Object representing a CSS rule-set.




PreviousNext

Related