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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:38:53+00:00 2026-05-28T16:38:53+00:00

Is it possible to get the CSSStyleSheet object ( document.styleSheets[0] ) from a HTMLStyleElement

  • 0

Is it possible to get the CSSStyleSheet object (document.styleSheets[0]) from a HTMLStyleElement (document.createElement('style')) ?

I would like to dynamically add css rules to a not-inserted-in-the-document-yet <style> element.

  • 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-28T16:38:54+00:00Added an answer on May 28, 2026 at 4:38 pm

    You can add rules before you add the style element to the document.

    A couple notes-

    Older IE browsers cannot add child nodes to a style element, so assign to the element’s styleSheet.csstext property for them.
    Make sure you append the new element to the head of the document.

    function addStyle(css, media1, title1){
        var el= document.createElement('style');
        el.type= 'text/css';
        if(media1) el.media= media1;
        if(title1) el.title= title1;
        if(el.styleSheet) el.styleSheet.cssText= css;//IE
        else{
            el.appendChild(document.createTextNode(css));
        }
        //return el without the next line if you want to append it later
        return document.getElementsByTagName('head')[0].appendChild(el);
    
    }
    
    var cs1= [
        '#yw_psq, #yw_psq h2{background-color: green; color: white;}',
        '#yw_psq_div{margin: 1ex; position: relative; text-align: center;}',
        '#ps_counter{color: white; margin: 1ex 0 0 0; text-align: center;}',
        '#pzsq_grid  button{cursor: pointer; font-size: 1.2em; width: 100%;}',
        '#delaySpan{font-weight: bold; margin-left: 1em;}'
    ]
    
    addStyle(cs1.join('\n'),'screen','yw_psq');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get the originating port from an ActionExecutingContext object? If so,
Hi I would like to ask if its possible get array with clear data
Is it possible to get the offset from end row? Like some kind of
Possible Duplicate: Get session object from sessionID in ASP.Net C# How to get Session
Possible Duplicate: Get and Parse CSV file in android I would like to store
It's possible get each row as an object like in ezSQL? For example, ezSQL
Possible Duplicate: Get all files from VSS for a given date? I need to
Possible Duplicate: Get output from a process Executing DOS commands from Java I am
Possible Duplicate: get image from base64 string I tried header('Content-Type: image/png'); echo base64_decode($data);` But
Is it possible get the assembly information from an imported MEF function? I need

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.