Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4001218
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:52:40+00:00 2026-05-20T07:52:40+00:00

How to get all DEFINED CSS Selectors for a given DOM Element using jQuery?

  • 0

How to get all DEFINED CSS Selectors for a given DOM Element using jQuery?

With defined I mean all CSS Selectors which are used in any of the Stylesheets applied to the document.

In a way, this is similar to the feature implemented by FireBug where in it shows all the Applied CSS Selectors for a selected DOM Element.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:52:40+00:00Added an answer on May 20, 2026 at 7:52 am

    From this answer you might be able to get what you are looking for by looping through the cssRules property.

    var myElement = $("#content");
    for (var x = 0; x < document.styleSheets.length; x++) {
        var rules = document.styleSheets[x].cssRules;
        for (var i = 0; i < rules.length; i++) {
            if (myElement.is(rules[i].selectorText)) {
                $("ul").append("<li>" + rules[i].selectorText + "</li>");
            }
        }
    }
    

    Given the following dom:

    <div>
        <div id="content">
        </div>
    </div>
    

    And css rules:

    div
    {
        background-color:black;
    }
    #content{
        height:50px;
        width:50px;
    }
    div > div
    {
        border: solid 1px red;
    }
    

    We would get a matched rule set of:

    body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form,fieldset, input, textarea, p,
    blockquote, th, td div
    #content 
    div > div
    

    Example on jsfiddle. Not sure how well this will work for all scenarios but might be something to look at if it will fit your needs.

    Updated with a slightly more complete example…

    $(document).click(function(event) {
        var rules = GetAppliedCssRules($(event.target));
        var $ul = $("#rules").empty();
        $.each(rules, function() {
            $ul.append("<li>" + this + "</li>");
        });
        event.preventDefault();
    });
    
    function GetAppliedCssRules($element) {
        var appliedRules = [];
        for (var x = 0; x < document.styleSheets.length; x++) {
            var rules = document.styleSheets[x].cssRules;
            for (var i = 0; i < rules.length; i++) {
                if ($element.is(rules[i].selectorText)) {
                    appliedRules.push(rules[i].selectorText);
                }
            }
        }
        return appliedRules;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I get a list of all the tables defined for the database
We need to get all the instances of objects that implement a given interface
How can I get all items from a specific calendar (for a specific date).
I'm trying to get all the direct reports of a User through Active Directory,
I'd like to get all the permutations of swapped characters pairs of a string.
I'm trying to get all property names / values from an Outlook item. I
I need to get all dlls in my application root directory. What is the
I would like to get all the instances of an object of a certain
Is there a method to get all of the .aspx files in my website?
Is there a way in C# to: Get all the properties of a class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.