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

The Archive Base Latest Questions

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

My research into the base HTML DOM element says this about any DOM element’s

  • 0

My research into the base HTML DOM element says this about any DOM element’s “style” property
(from http://www.w3schools.com/jsref/dom_obj_all.asp):

   "style --    Sets or returns the style attribute of an element"

The ‘label’ tag is a dom element. And thus it has a ‘style’ property. As it points out on the w3schools link
above, all dom elements have a ‘style’ property.

And in fact, here I’m setting (inline) the ‘style’ property for a label tag — and this works fine:

    <label for="itemImageId" style="color: gray" id="labelForImageUploadID">Item image</label>

The label text color is gray at page load time.

Under a certain condition (user has indicated they’re ready to select an image to upload) —
I need to show the upload as ‘enabled’ by changing the initial gray text color of the above to black.

Do I know I could use a css class for this label’s text color and use the ‘className’ property to dynamically
alter the css class of the above? You bet I do. Tonight though I’m holding this DOM element’s feet
to the fire. I just have one ‘style’ attribute to change (text color) and don’t want to add a class just for it
— what I’m trying here should work according to the docs.

I want to know why I can’t use the ‘style’ property as the DOM says I can — “get” AND “set” DOM element’s
properties.

Here I’m “set”-ing the ‘style’ property of my — this does NOTHING — the label text remains gray:

    document.getElementById('labelForImageUploadID').style = "color: rgb(0,0,0)";

Nor does this change the color from gray to black:

    document.getElementById('labelForImageUploadID').style = "color: black";

The above code executes (in javascript) after the label is already visible on the page, and in response to an onclick event of a button on the form that the label is also a part of.

Is there a bug in the ability to “set” a DOM element’s ‘style’ property?
According to http://www.w3schools.com/jsref/dom_obj_all.asp,

   "HTMLElement Object

    The following properties, and methods can be used on all HTML elements."

        (other properties here.....)
   "style --    Sets or returns the style attribute of an element"
       (still other properties here......)

So why can’t I change the element’s ‘style’ property then in my code above?

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

    Upon reviewing this answer in 2017, the original example of setting the whole style string does work correctly. I don’t know what the problem was,
    but the examples below are still valid approaches.


    Setting a style with JavaScript usually follows the following format:

    document.getElementById("abc").style.[css property name in camel case] = "[value]";
    
    • Basic Example
    • Event-triggered Example

    If using jQuery, it becomes a bit cleaner:

    // find all elements with the tag name "bar" that are direct 
    // descendants of an element with the class name "foo"
    $(".foo > BAR").css("color", "red");
    
    // set multiple properties
    $(".foo > BAR").css({ color: "red", "background-color": "beige" });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done a bit of research into this and it seems that the
Have done some research into this topic, but found no relevant answers. What I
I have done a great deal of research into this topic of an 'event
So I've done some research into this issue, but I haven't found anything similar
I've been doing some research into this problem but haven't yet been able to
I'm doing some research into databases and I'm looking at some limitations of relational
I've done some research into server push with javascript and have found the general
I'm doing some research into using log4net, and I found the IObjectRenderer interface interesting.
I'm doing research into a web API for my company, and it's starting to
I’m doing some research into the capabilities of Windows Azure for an European company.

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.