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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:51:58+00:00 2026-05-11T05:51:58+00:00

It’s easy to set inline CSS values with javascript. If I want to change

  • 0

It’s easy to set inline CSS values with javascript. If I want to change the width and I have html like this:

<div style='width: 10px'></div> 

All I need to do is:

document.getElementById('id').style.width = value; 

It will change the inline stylesheet values. Normally this isn’t a problem, because the inline style overrides the stylesheet. Example:

<style>    #tId {       width: 50%;    } </style>  <div id='tId'></div> 

Using this Javascript:

document.getElementById('tId').style.width = '30%'; 

I get the following:

<style>    #tId {       width: 50%;    } </style>  <div id='tId' style='width: 30%';></div> 

This is a problem, because not only do I not want to change inline values, If I look for the width before I set it, when I have:

<div id='tId'></div> 

The value returned is Null, so if I have Javascript that needs to know the width of something to do some logic (I increase the width by 1%, not to a specific value), getting back Null when I expect the string ‘50%’ doesn’t really work.

So my question: I have values in a CSS style that are not located inline, how can I get these values? How can I modify the style instead of the inline values, given an id?

  • 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. 2026-05-11T05:51:59+00:00Added an answer on May 11, 2026 at 5:51 am

    Ok, it sounds like you want to change the global CSS so which will effictively change all elements of a peticular style at once. I’ve recently learned how to do this myself from a Shawn Olson tutorial. You can directly reference his code here.

    Here is the summary:

    You can retrieve the stylesheets via document.styleSheets. This will actually return an array of all the stylesheets in your page, but you can tell which one you are on via the document.styleSheets[styleIndex].href property. Once you have found the stylesheet you want to edit, you need to get the array of rules. This is called ‘rules’ in IE and ‘cssRules’ in most other browsers. The way to tell what CSSRule you are on is by the selectorText property. The working code looks something like this:

    var cssRuleCode = document.all ? 'rules' : 'cssRules'; //account for IE and FF var rule = document.styleSheets[styleIndex][cssRuleCode][ruleIndex]; var selector = rule.selectorText;  //maybe '#tId' var value = rule.value;            //both selectorText and value are settable. 

    Let me know how this works for ya, and please comment if you see any errors.

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

Sidebar

Ask A Question

Stats

  • Questions 147k
  • Answers 147k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The answer primarily depends on the type of application you… May 12, 2026 at 9:14 am
  • Editorial Team
    Editorial Team added an answer Some possibilities: Some other part of your code overwrote the… May 12, 2026 at 9:14 am
  • Editorial Team
    Editorial Team added an answer I've achieved a working example! The main idea received from… May 12, 2026 at 9:14 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
It seems to me obfuscation is an idea that falls somewhere in the security

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.