473,796 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

default style.backgroun dColor value

Hey,

Is it possible to get the default value of an element's
style.backgroun dColor 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.formna me.example.styl e.backgroundCol or;

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 6630
DU
Philip wrote:
Hey,

Is it possible to get the default value of an element's
style.backgroun dColor 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.formna me.example.styl e.backgroundCol or;

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.backgrou ndColor = " +
document.styleS heets[0].cssRules[1].style.backgrou ndColor);
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 heightStyleValu e = "unable to process";
if("cssRules" in document.styleS heets[0]) // DOM 2 CSS compliant browsers
{
var heightStyleValu e = document.styleS heets[0].cssRules[3].style.height;
}
else if("rules" in document.styleS heets[0]) // MSIE 5+
{
var heightStyleValu e = document.styleS heets[0].rules[3].style.height;
};

alert(heightSty leValue);
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
1577
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 specify and create a default config file. In other words, when the developer puts a new element in the schema
4
102938
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 <OPTION>Test 2 <OPTION>Test 3 <OPTION>Test 4
5
17713
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 fancy style, but the onclick fails to do anything no matter what permutation of parameters I try. <input type=button style=background-color:yellow;color:blue;font-family:Arial;font-style:italic;font-weight:bold name="xyz" value="CHANGE COLOUR"...
3
3590
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 default look. Once I change a button's style to something else what is the style setting to revert them back to this default? EX: Button starts at default.
3
4598
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 : <script language="javascript"> function highLigth (x) { x.style.borderWidth = '5px';
5
8743
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" class="select" style="background:yellow"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option>
6
10730
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 graphic, with CSS only. the product is finished. whenever i select a color, its color will be displayed in a box whose id name is contained in variable "color_box" and the equivalent color value will appear in a text box with id contained in the variable...
9
1277
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) document.getElementById("inner").style.backgroundColor = GetStyle("box", "backgroundColor"); document.getElementById("box").style.backgroundColor = "transparent"; <div id="box" style="width: 100px; height: 100px; background-color: Red">
6
1955
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, I thought if I put played around with the checked box function, I'd get what I want, but I don't. I tried changing this document.getElementById('markerImage').disabled = true; to this document.getElementById('markerImage').disabled =...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9533
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6796
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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 we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.