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 7890517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:22:29+00:00 2026-06-03T06:22:29+00:00

.test { color:Red; width: 100px; } var r = document.styleSheets[index].rules; r[0].selectorText => Here we

  • 0
.test
{
 color:Red;
 width: 100px;
}

   var r = document.styleSheets[index].rules;   

   r[0].selectorText => Here we get ".test";

Now i want to get access of all .test properties (in this case color and width) in an array and its values ( in this case Red & 100px ).How can i do this?

  • 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-06-03T06:22:31+00:00Added an answer on June 3, 2026 at 6:22 am

    You want the .cssText of the CSSStyleRule. (You can find this yourself with console.log(document.styleSheets[2]) on this page and diving through the items in the console of Chrome or Firebug.)

    Also note that while .rules works in some browsers, the DOM Level 2 CSS binding is .cssRules.

    Edit: If you need access to individual styles, then use the .style property. Again, you could see if this you used the developer console.

    var sheet = document.styleSheets[2];
    var rules = sheet.cssRules[1];
    console.log( rules ); // Lots of properties
    console.log( Object.keys(rules) );
    // ["parentRule", "cssText", "type", "selectorText", "style", "parentStyleSheet"]
    console.log( rules.style.display ); // "none"
    

    If you want to see just the styles that are applied in this rule, you’ll have to either iterate through the properties of the .style collection (which includes properties that were not explicitly set) and check for empty values, or else you’ll need to parse the cssText yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
<style> #test{ background-color:#b10515; width=440px; } </style> <script> ... ... cell[k]=document.createElement('td'); var cont = document.createElement('a');
I want to make a simple test programm which set the color of the
HTML: <div id=div_id><div class=div_class><p>test</p> </div> <div class=two> <p>asd</p></div> </div> CSS: #div_id p { color:red;
I am wondering is there any way we can test the font size/color of
<div style=background-color:black> <div style=float:right> Test message </div> <div> This will show 'Test message' with
-------test code(test.html)------------ <!DOCTYPE html> <html> <head> <style> *{padding:0px;margin:0px;} </style> </head> <body style=background-color:orange;> <b onmousemove=tip(this);>A</b>
see the following example: <script language=javascript type=text/JavaScript> function testPrecision() { document.getElementById(test).style.left = 30.176283764px; alert(document.getElementById(test).style.left);
I've been struggling with this on and of for ages now. What I want
I've created this test-page: http://uploads.dennismadsen.com/width.html <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html

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.