Open In App
Related Articles

CSSStyleDeclaration parentRule Property

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The parentRule property is used to return the CSSRule Object that represents a CSS rule-set that contains selector and declaration block

Syntax: It is used to return the parentRule property.

object.parentRule

Return Value: It returns the CSSRule object. 

Example: To return the parentRule property

html




<!DOCTYPE html>
<html>
<head>
    <title>
        CSS | Style Declaration parentRule Property
    </title>
    <style>
        body {
            text-align: center;
        }
 
        h1 {
            color: green;
        }
 
        #p1 {
            color: green;
            font-size: 20;
        }
    </style>
</head>
 
<body>
    <h1>
        GeeksforGeeks
    </h1>
 
    <p id="p1">
        parentRule Property
    </p>
 
    <p>
        Click the button to
        return the parentRule property
    </p>
 
    <button onclick="myFunction()">
        Get parentRule
    </button>
 
    <p id="gfg"></p>
    <!-- Script to get parentRule property -->
    <script>
        function myFunction() {
            let x =
                document.styleSheets[
                    0].rules[2].style.parentRule.cssText;
            document.getElementById("gfg").innerHTML = x;
        }
    </script>
</body>
</html>


Output:

 

Supported Browsers: The browsers supported by Style Declaration parentRule Property are listed below:

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 9
  • Firefox 1
  • Opera 15
  • Safari 1

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 09 Jun, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials