473,657 Members | 2,476 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").bottoml ine.color);

or

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

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

Jul 23 '05 #1
3 2111
jo*********@yah oo.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").bottoml ine.color);
If you are trying to access a particular style property of an
element, use:

alert(document. getElementById( "myid").style.p roperty);

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(element ID) {
var eAtt = document.getEle mentById(elemen tID).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.bottomli ne.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.styleS heets[0].cssRule[0].style.cssText

or just the selector text (class name):

document.styleS heets[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.styleS heets[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*********@yah oo.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="aStringOf Text" content="blah blah blah">

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

var c = document.getEle mentsByTagName( '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.styleS heets[0].cssRule[0].style.cssText

works on Nescape but not in IE.


Yeah, sorry, the IE equivalent is:

document.styleS heets[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
2381
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 not working.. and I have no idea why. I can output the return value of getInsideWindowWidth with alert(getInsideWindowWidth();) and its working fine..
2
1169
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 like getElementById(id).style ? Is there any method sorta like getElementById(id).getStyle ? Thanks much.
6
1176
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 _CreateDate End Get
5
1942
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
2825
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 happens; the control looks the same as if the property were set to "Normal." Existing controls set to Transparent are still OK; I just can't make the new ones transparent. Does anybody have any idea what's up? Many thanks for any input. ...
1
1766
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 own form designer like tool and want to be able to load a class into a grid or table object for editing.
2
1166
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 definitely the RadioButtonList but I can not seem to get to the selectIndex property. When I do a Object.id it does however give me the correct name of the RadioButtonList id name. Just not sure of the syntax to get at the selectIndex property
4
2683
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 for each state. Each entry contains Name, postal abbreviation, etc. Just simple stuff to understand the mechanisms, syntax, etc. I'm now to the point where I've got a Master MDI form that opens one or more types of forms, I'm able to edit/save...
4
5630
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
8420
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
8324
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
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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
7353
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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...
1
2743
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
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.