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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:32:00+00:00 2026-05-26T04:32:00+00:00

It seems like using this function would be more portable or reliable, because the

  • 0

It seems like using this function would be more portable or reliable, because the alternative is to set an attribute:

element.style.setProperty(styleproperty, valuestring);
element.setAttribute('style',styleproperty+': '+valuestring+';');

The second method would also seem slightly more inefficient though that’s hardly a concern.

But at least on Chrome, the style does not update on the page unless I use the setAttribute method.

The reason why this is a bit of an issue, is that I have potentially many different separate style properties I want to modify independently of the others. I have to do a whole lot of string parsing and processing if I can’t make use of setProperty, removeProperty, etc. I have to pull out the style string, search it, modify it, and set it back in via setAttribute. Should work, but I don’t like it.

Is there a reason for this? Is this a bug? My guess is that setAttribute triggers something for the browser to perform a re-render. What is a suitable way to force this update that is generally browser-friendly?

  • 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-26T04:32:01+00:00Added an answer on May 26, 2026 at 4:32 am

    Setting the style attribute directly has consequences that may be undesirable: it will wipe out all existing styles set in the element’s style attribute, and setAttribute is broken in older IE (and compatibility modes in later IE). Much safer is to use the element’s style property directly to set only the style property you need:

    element.style[styleproperty] = valuestring;
    

    This will update the page immediately in all major browsers.

    One caveat: CSS style properties (generally using dashes, such as in background-color) do not map precisely to properties of the DOM element’s style object (generally camel case, such as in backgroundColor). There are also exceptions to this rule.

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

Sidebar

Related Questions

Based on this article , it seems like SO is using Javascript OpenID Selector
Can someone tell me how to change directories using FtpWebRequest? This seems like it
I have an entity and it seems like using DateTime as the Id would
I would like to animate a ScatterView Control using Expression Blend However, it seems
I have a problem with using the prefix, seems like whenever I use the
For iPhone game development, seems there are very like functions using CALayer and UIView,
Seems like my data is getting corrupted when using HTTPapp.HTMLEncode( string ): String; HTMLEncode(
I would like to apply some function on each row of a dataframe in
I'm trying to wtire unit tests for a function that looks something like this:
I have a project which I would like to make more use of smart

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.