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

  • Home
  • SEARCH
  • 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 7875247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:57:03+00:00 2026-06-03T02:57:03+00:00

Firefox and Chrome let me create a <style> element and populate it, all from

  • 0

Firefox and Chrome let me create a <style> element and populate it, all from JavaScript. I could swear that in the past I’ve done that in IE (like, IE6), in different circumstances. But now I can’t get IE (7 or 8; haven’t tried 9) to let me set it at all.

I have this recollection of a “cssText” property, but now in the (mysteriously diminished; does anybody know what happened to the MSDN documentation site?) MSDN docs that only shows up as a part of the stylesheet API and not as a DOM element thing.

So: is it at all possible to create and populate a <style> element in Internet Explorer?

Here is a trivial jsfiddle example, with the following jQuery code:

$('head').append($('<style/>', { html: 'div { color: red; }' }));

Works fine in Firefox, Chrome, and Opera. (I guess I should try Android and iOS while I’m at it.)

edit — yes, I’ve tried setting “text” instead of “html”, and it doesn’t help. Trying to set “innerText” without jQuery also doesn’t work.

  • 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-03T02:57:04+00:00Added an answer on June 3, 2026 at 2:57 am

    Here is how I’ve done this before. I’ve pretty much copied this straight out of some old code of mine, but if I remember correctly, the styleSheet property is only used by IE, and as you mentioned, that’s when you need to use cssText:

    var styleElem = document.createElement("style");
    styleElem.type = "text/css";
    styleRules = document.createTextNode(".someClass { color: red; }");
    if(styleElem.styleSheet) {
        styleElem.styleSheet.cssText = styleRules.nodeValue;
    }
    else {
        styleElem.appendChild(styleRules);
    }
    document.getElementsByTagName("head")[0].appendChild(styleElem);​
    

    Here’s a working example (tested in latest Chrome and IE6).

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

Sidebar

Related Questions

I have the following script that works well in Firefox and Chrome (not sure
I have the following code that works on Firefox and Chrome $("#adicionarItem").click(function(){ $.ajax({ type:
Our app supports different browser version from IE to Firefox to Chrome. Now, some
Are there any extensions that are hybrid on both Firefox and Chrome platform? I
I'm used to debugging JavaScript in Chrome or Firefox just because their built in
Im currently making a firefox extension that will let you choose what tabs you
I have a page ([LINK REMOVED]) that works completely well in FireFox and Chrome,
Is there a way to select all CSS rules of an element with JavaScript?
In Firefox and Chrome, the filters_area div is correctly left-aligned under the tabs div,
This works in Firefox and Chrome, but fails in IE. It does show results

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.