473,513 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

default style.backgroundColor value

Hey,

Is it possible to get the default value of an element's
style.backgroundColor property that's set in a css class?

Example, since I'm very tired and can't word that any better ;)

input.example { background-color: #fff }

and the javascript:
var original = document.formname.example.style.backgroundColor;

returns null. Any ideas?

I should stress at this point any hard coded colours are not an option,
since the site is themeable and I don't want to introduce any conflicts.

Thanks in advance.

--
Philip
email-o-mask-o: spam->mouse

Jul 20 '05 #1
1 6598
DU
Philip wrote:
Hey,

Is it possible to get the default value of an element's
style.backgroundColor property that's set in a css class?

Example, since I'm very tired and can't word that any better ;)

input.example { background-color: #fff }

You need to know which styleSheets it involves in the ordered collection
of style sheets and which cssRules is involved in the cssRules list.
http://www.w3.org/TR/2000/REC-DOM-Le...le-styleSheets
http://www.w3.org/TR/2000/REC-DOM-Le...Sheet-cssRules
and the javascript:
var original = document.formname.example.style.backgroundColor;

example is a className while formname is presumably the form's name. The
2 refer to 2 different and incompatible interfaces.
returns null. Any ideas?

Assuming the following is your stylesheet (and you only have 1 style sheet):

<style type="text/css">
body {margin:16px; padding:0px; color:black; background-color:white;}
input.example { background-color: #fff }
p#footer img , p#validation img {margin:0 0.5em;}
p#validation img {width:88px; height:31px;}
</style>

then
alert("document.styleSheets[0].cssRules[1].style.backgroundColor = " +
document.styleSheets[0].cssRules[1].style.backgroundColor);
should return/output #fff in DOM 2 CSS compliant browsers. For MSIE 5+,
then use rules instead.
E.g.: show the height value in the last rule:

var heightStyleValue = "unable to process";
if("cssRules" in document.styleSheets[0]) // DOM 2 CSS compliant browsers
{
var heightStyleValue = document.styleSheets[0].cssRules[3].style.height;
}
else if("rules" in document.styleSheets[0]) // MSIE 5+
{
var heightStyleValue = document.styleSheets[0].rules[3].style.height;
};

alert(heightStyleValue);
should alert "31px".
I should stress at this point any hard coded colours are not an option,
since the site is themeable and I don't want to introduce any conflicts.

Thanks in advance.


DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1567
by: inquirydog | last post by:
Hi- I am using xml to hold configuration data for a project, and using schema to define what the configuration file should look like. I wanted to get some advice on an intelligant way to...
4
102924
by: Jeff Anderson | last post by:
Is there a style for a select option's "selected" color? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1...
5
17662
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a...
3
3565
by: Rick Brandt | last post by:
I am using some buttons to hide/show various divs and am changing the style of the button to indicate which button's view is "active". My problem is that for the non-active buttons I want the...
3
4569
by: alexjaquet | last post by:
Hi, I've in my web pages an affectation to this property but it's doesn't work (same for all the others properties I'm trying to update): here is the complete function I call on mouseover : ...
5
8721
by: Isha | last post by:
Hi all, I wanted to change the background color for only the first option in a select box, but following changed the background color for the whole dropdown box. <select name="alltags"...
6
10691
by: fallen angel | last post by:
halu there!! i'm a 1month experienced java scripter but got a good hang of it already. hehehe.. i developed a "color selection" tool, similar to the one in flash when you choose a color for a...
9
1265
by: Piotr K | last post by:
Ok, I tried simply everything that came to my mind and now I ran out of ideas, but to the point - take a look at the code below // GetStyle returns given style value (works fine)...
6
1930
tpgames
by: tpgames | last post by:
I'm trying to get a maze to default to always giving me the image as the marker and never give me the color as the marker. The code requires you to check a box to get the image marker to be used. So,...
0
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.