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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:01:20+00:00 2026-05-25T00:01:20+00:00

I have created several shapes with CSS, each shape is contained in an element

  • 0

I have created several shapes with CSS, each shape is contained in an element with an id, for example id=”square”. What I want is the following: If I click on the shape, I would like to display its CSS rules in a textarea.

Here’s my HTML:

<ul>
    <li><div id="square" class="box"> parallelogram </div></li>
    <li><div id="parallelogram" class="box"> parallelogram </div></li>
    <li><div id="parallelogram2" class="box"> parallelogram2 </div></li>
</ul>
<textarea name="show" id="show" cols="30" rows="10"></textarea>

And my CSS:

#square {
  width: 100px;
  height: 100px;
  background: blue;
}

#parallelogram {
  width:100px;
  height:70px;
  background:blue;
  -webkit-transform:skew(20deg);
  -moz-transform:skew(20deg);
  -o-transform:skew(20deg);
  transform:skew(20deg);
}

#parallelogram2 {
  width:100px;
  height:70px;
  background:blue;
  -webkit-transform:skew(-20deg);
  -moz-transform:skew(-20deg);
  -o-transform:skew(-20deg);
  transform:skew(-20deg);
}

And the jQuery code I currently have:

$(".box").click(function () {
  var id = $(this).parents().attr('id');
  var cssrules=document.styleSheets[0].rules["id"].style.cssText;
  $("#show").html("cssrules");
});

Also see this jsFiddle. Here’s another one with all my shapes.

  • 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-25T00:01:21+00:00Added an answer on May 25, 2026 at 12:01 am

    The whitespace issues are actually preventing this from working at all – there is a difference between $(“#show”) and $(“#show “), so you should really be more careful with this. I fixed the markup:

    <body> 
      <div class="main"> 
        <ul> 
          <li><div id="square" class="box">parallelogram0</div></li> 
          <li><div id="parallelogram" class="box">parallelogram1</div></li> 
          <li><div id="parallelogram2" class="box">parallelogram2</div></li> 
        </ul> 
      </div> 
      <textarea name="show" id="show " cols="30" rows="10"></textarea> 
    

    To get your inline style sheet, you should iterate over document.styleSheets and grab the one that has an href attribute with value null – the other ones are external style sheets. Since all your elements are referenced by id and the corresponding CSS rules start with # we can get the rule corresponding to a shape by testing whether the selectorText attribute of a rule starts with “#”:

    for (var i=0; i<document.styleSheets.length; i++) {
        if (document.styleSheets[i].href === null)
            var sheet = document.styleSheets[i];
    }
    
    $(".box").click(function() {
        var id = $(this).attr('id');
        var rules = sheet.cssRules || sheet.rules;
        for (var i=0; i<rules.length; i++) {
            if (rules[i].selectorText.indexOf("#"+id) == 0) {
                var rule = rules[i];
                break;
            }
        }
        $("#show").val(rule.cssText);
    }); 
    

    You can access the style sheets only by index, they’re held in an array. Finally, you have to set the value of the textarea, not its html.

    Here is a jsfiddle illustrating it.

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

Sidebar

Related Questions

I have created several shared example groups for Rspec which I would like to
I have created several UI elements in the viewDidLoad method. I want to change
I have a listview with several items that are created dynamically, each has two
I'm using RaphaelJS 2.0 to create several shapes in a div. Each shape needs
I have created a CALayer (I added several shapes to the layer, but ultimately,
Our business deals with houses and over the years we have created several business
We have an ADP project created several years ago using Access 2000. This project
I have created a file argument.pl which takes several arguments first of which should
I have created a Python module that creates and populates several SQLite tables. Now,
I'm trying to insert several newly created items to the database. I have a

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.