473,503 Members | 12,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Style Property with ID

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.c olor);

or

alert(document.all["myid"].style.bottomline.color);

The code above doesn't work on IE and Netscape 7.1...
Any hints???

Jul 23 '05 #1
3 2096
jo*********@yahoo.com wrote:
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.c olor);
If you are trying to access a particular style property of an
element, use:

alert(document.getElementById("myid").style.proper ty);

where "property" is the style property you are trying to access.
You must change hyphenated style properties to "camelCase", e.g.
background-color becomes backgroundColor.

If you want to get all the style properties to see what's set,
get the element attributes collection and print out just the
style. e.g.

function doStyle(elementID) {
var eAtt = document.getElementById(elementID).attributes;
for (var i=0, len=eAtt.length; i<len; i++) {
if(eAtt[i].name == 'style')
alert(eAtt[i].value);
}
}

or

alert(document.all["myid"].style.bottomline.color);

The code above doesn't work on IE and Netscape 7.1...


Because there is no style property for "bottomline". A list of
the DOM CSS properties that work with Mozilla/Firefox are here:
<URL:http://www.mozilla.org/docs/dom/domref/dom_style_ref18.html#1002335>

If, on the other hand, you are trying get the *class* bottomline
and it's attributes that you have defined in the style sheet,
that is a totally different thing. You must access the
styleSheets collection, then the cssRules collection, then to
isolate the particular rule, look for the selectorText
(essentially equivalent to the class name, including the leading
'.', '#', etc.). But beware, IE puts an asterisk (*) in front of
the selectorText.

Say the following class called "aClass" is the first rule in the
first style sheet:

.aClass {color: grey; background-color: red;}

You can get all the style properties as:

document.styleSheets[0].cssRule[0].style.cssText

or just the selector text (class name):

document.styleSheets[0].cssRules[0].selectorText;

But beware, that just gets the definition from the style sheet,
it doesn't tell you what is actually set on the element.

Have a look around here:
<URL:http://www.mozilla.org/docs/dom/domref/dom_style_ref14.html#998514>
--
Rob
Jul 23 '05 #2
First, thanks for your reply Rob.

Second, i will tell you the truth.

What i need is to access strings out of my server and include it on my
html.

I thougth in puting this strings on a text fileld of an style and
access it.

Why?

I can't use <scripts src="http://..."> because of security risk.

So, i am trying to include an accessable and not runable code on my
html.

I know that ActiveX do it and java too but for compatibility reasons i
prefered css.

Tried your code:

document.styleSheets[0].cssRule[0].style.cssText

works on Nescape but not in IE.

Frames doesn't sound nice too.

If you have an idea on how can i do this external including, please
post it.

Thank you again.

Jul 23 '05 #3
jo*********@yahoo.com wrote:
First, thanks for your reply Rob.

Second, i will tell you the truth.

What i need is to access strings out of my server and include it on my
html.

I thougth in puting this strings on a text fileld of an style and
access it.

Why?

I can't use <scripts src="http://..."> because of security risk.
I don't really understand what you are doing. Presumably a server
is generating strings for some purpose and putting them in a
file. Do you then want the browser to be able to securely access
the same file?

Maybe your best option is to investigate XMLHTTP - do a search on
this newsgroup and post anew for more help.
So, i am trying to include an accessable and not runable code on my
html.
Why not use a meta tag? e.g.

<meta name="aStringOfText" content="blah blah blah">

Then use document.getElementsByTagName('meta') to get at it?

var c = document.getElementsByTagName('meta')['aStringOfText']
alert(c.content); // blah blah blah

With appropriate feature detection added. Of course, then the
user will see the content in the HTML source, so this may raise
your security issues again.

I know that ActiveX do it and java too but for compatibility reasons i
prefered css.
If you get this to work via CSS I think that's called a hack
or kludge.

Tried your code:

document.styleSheets[0].cssRule[0].style.cssText

works on Nescape but not in IE.


Yeah, sorry, the IE equivalent is:

document.styleSheets[0].rules[0].style.cssText

More IE stuff is here:
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_stylesheet.asp>

You need to use feature detection to sort which method to use (IE
or other). And IE 6 seems to have dropped the leading '*' on
selectorText.

The equivalent w3c spec is here:
<URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleSheet-cssRules>
--
Rob
Jul 23 '05 #4

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

Similar topics

3
2375
by: Axel Siebenwirth | last post by:
Hi, I am desperately trying to assign a variable or rather the return value of a function to a style property. document.getElementById("line").style.width=getInsideWindowWidth(); But it is...
2
1159
by: tan.dalat | last post by:
Hi, Due to a restriction on the host, I'm not allowed to use .style, so I'm unable to manipulate the style property of the element. Is there any other way to get to style without using something...
6
1166
by: Noggin The Nog | last post by:
Hi I'm sure this is a simple problem ... for someone! I have a class which exposes a property which is another object (SmartDate): Public Property CreateDate() As SmartDate Get Return...
5
1937
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
1
2821
by: jboldrick | last post by:
I'm using Access 2003. I seem to have suddenly lost the ability to set the Back Style property of tab controls to "Transparent." Or rather, I can set the property value as "Transparent" but nothing...
1
1761
by: JDeats | last post by:
Using VS.NET 2003 and the 1.1 Framework, is there a control I can add to a WinForm that will allow me to mimic the functionality of the Visual Studio.NET style property grid.. I trying to create my...
2
1159
by: barry | last post by:
I am using the animation extender in asp.net ajax and have a RadioButtonList in a div and access it in javascript through the extender. The object passed into the javascript function is...
4
2674
by: nottarealaddress | last post by:
I'm trying to get my feet wet in VB2005 (our new standard at work after officially stopping new development in VB6 about a month ago). I'm working with a simple sql 2005 table of 50 entries, one...
4
5625
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
7212
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,...
0
7098
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
7017
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...
1
5026
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
4696
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
3186
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
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
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 ...
0
405
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.