473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

retriving property from style sheet

Is it possible to retrieve a property from a defined style in a style sheet?

for example, if i have:

<style>
.mystyle {background-color:#ff0000}
</style>

how can retrieve the background color for that style?

is there something like: document.mystyle.background-color (?)

thanks in advance.
alex.
Jul 23 '05 #1
2 1224


alex bazan wrote:
Is it possible to retrieve a property from a defined style in a style
sheet?

for example, if i have:

<style>
.mystyle {background-color:#ff0000}
</style>

how can retrieve the background color for that style?


In Netscape 6 and later, Mozilla, IE 4 and later there is a property
document.styleSheets
thus if you have exactly one embedded CSS stylesheet
<style type="text/css">
.mystyle {background-color:#ff0000}
</style>
you can access it as
var stylesheet = document.styleSheets ? document.styleSheets[0] : null;
then in Mozilla and other W3C DOM compliant browsers each sheet has a
property cssRules for the rules, in IE there is a property rules e.g.
if (stylesheet) {
var rules = stylesheet.cssRules ? stylesheet.cssRules :
stylesheet.rules;
the first (and only rule in your example) has the index 0 e.g.
if (rules && rules[0]) {
rules[0].style.backgroundColor = '#00ff00';
}
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
En/na Martin Honnen ha escrit:

In Netscape 6 and later, Mozilla, IE 4 and later there is a property
document.styleSheets


Thanks, finally i got the right "googlequery" and found a script with a
similar code
(http://chapnickman.com/2005/03/14/ge...th-javascript/)

At last, i opted for a PHP solution.
thaks for all.
alex.
Jul 23 '05 #3

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

Similar topics

2
by: Mark | last post by:
Hi - I want to allow users of an intranet application, to select their own colours etc. So I have a tbale in my database, which has fields called bgcolour, fontcolour etc. As I want all pages...
4
by: Julie Siebel | last post by:
Apologies...I'm sure this has been asked before, but I can't seem to come up with the correct Google search terms. While my problem is with stylesheets, the errors are being caused by my...
2
by: Niyazi | last post by:
Hi, I have to retrieve a data from AS400 DB2 and after working with data I have to export into one of existing Excel file. I can connect into specific library in AS400 DB2 using AS400...
6
by: Shawn Modersohn | last post by:
<script type="text/javascript"> var browser=navigator.appName if (browswer="Microsoft Internet Explorer") document.styleSheets.rules.style.left="50px" </script> IE does exactely what I hoped...
3
by: joealey2003 | last post by:
Hi all... I included a css file on my html and i need to check some properties. The html is: <style id="myid" src="mycsspage.css"> </style> Now i need something to access it like: ...
4
by: patrick j | last post by:
Hi First I must apologise to Mr. Dorayme for my use of his web-page as the example for my question. In order assist in making him feel better I'll mention it is an excellent article. However...
4
by: Taras_96 | last post by:
Hi everyone, Has anyone ever had problems with random CSS properties being assigned? The other day I created a span, coloured it red, and for some reason the 'text-decoration: captilization'...
4
by: fjm | last post by:
Hello everyone. I’d like to know how to handle multiple style sheets. I have css tabs that have a style sheet and then I also have a separate style sheet for the content that goes inside the tab. ...
4
Frinavale
by: Frinavale | last post by:
So a while ago I created a Tab Strip Control (before the AjaxToolkit had theirs otherwise I would have probably just used theirs). When I looked at the AjaxToolkit control to see how they got...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.