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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:21:53+00:00 2026-05-24T19:21:53+00:00

I am creating a style element and I need to put some CSS into

  • 0

I am creating a style element and I need to put some CSS into it. The below code works in Chrome, Safari and FF, but fails in IE8:

var styleElement = document.createElement("style");

styleElement.type = "text/css";

styleElement.innerHTML = "body{background:red}";

document.head.appendChild(styleElement);

In IE8, the code fails when it comes to the innerHTML part. I’ve tried doing:

var inner = document.createTextNode("body{background:red}");

styleElement.appendChild(inner);

But this also fails with “Unexpected call to method or property access.”
I’m looking for a workaround or fix.

  • 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-24T19:21:55+00:00Added an answer on May 24, 2026 at 7:21 pm

    Use .styleSheet.cssText

    NOTE: this seems to be REALLY slow in IE8 compared to modifying individual elements style.

    Is there a faster way to modify style sheets dynamically in IE?

    This is slow in IE8:

    styleElement.styleSheet.cssText = "body{background:red}";
    

    This is also slow in IE8 (assumes the style object to be modified is the 1st style element in the head):

    document.styleSheets[0].cssText = "body{background:red}";
    

    This is fast in IE8:

    document.body.style.background = "red";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a security expert by any means, but I favor creating REST-style web
I'm having some difficulties creating a javascript appointment style calendar. While it does render,
I am looking for some framework or toolkit (style drag and drop) for creating
Ive been wondering... in CSS are there any differences between creating a style class
I am creating a div in Chrome, like this: <div style=position:absolute;background:#000;width:150px;height:150px></div> When i inspect
When creating a Style, is it possible to set the ControlTemplate property to a
I'm creating eBay style search panes that allow users to narrow their results set
I am using creating a server/client style program, and it uses tcp connections. Now,
I've been having a problem creating a checklist in the style of the TouchCells
I am restyling the default tooltip by creating an Application level typed style resource

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.