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

Home Posts Topics Members FAQ

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.mystyl e.background-color (?)

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


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.styleS heets
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.styleS heets ? document.styleS heets[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.cssR ules ? stylesheet.cssR ules :
stylesheet.rule s;
the first (and only rule in your example) has the index 0 e.g.
if (rules && rules[0]) {
rules[0].style.backgrou ndColor = '#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.styleS heets


Thanks, finally i got the right "googlequer y" 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
2017
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 to get the users colours, I have an includes file at the top of each page: <!--#include file="userconfig.asp" --> This is:
4
2190
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 javascript, so this seemed a more appropriate place to post. I'm using a media=print style sheet to do a version of a web page that I am building. Currently, I'm working on the IE version. I have an HTML page and 2 style sheets which all validate...
2
5346
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 Client-Access v5.2 program using (in VB.NET) ODBC driver (DSN Name …) . I can retrieve datam work on it using VB.NET and I can send into 'NEW' Excel file. My first problem starts here:
6
1446
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 this script would do. Netscape says that document.styleSheets.rules has no properties. Since this script is targeted at IE anyway, should I be concerned? Also, is this script way oversimplified? All the css rule does is shift an image slightly to
3
2121
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: alert(document.getElementById("myid").bottomline.color);
4
5218
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 what I am enquiring about is how to make what he has done work in IE 6. Here is the web-page:
4
1905
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' property was set!!! I got aroudn this by manually setting that property to none. I do not use this value for this property ANYWHERE in my style sheet! Another similar problem has cropped up. On a particular member's computer the background for...
4
2403
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. The problem I am running into is that the tab style sheet uses attributes in the html and body and so does the content style sheet. Each one is specific to its content. The tab style sheet seems to take precedence over the content style sheet because...
4
5635
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 around this problem I discovered that they're using Animations. I don't want to bloat my control with the Ajaxtoolkit's Animation stuff though. I guess I should tell you what the problem is. I have a TabStrip custom control. It's a Table that has...
0
9529
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
10231
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
10013
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
6792
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
5443
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4119
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
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
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.