Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Class Attributes 1

Status
Not open for further replies.

hc98br

ISP
Aug 14, 2003
46
I'm after a snippet of code that will allow me to get the attributes of a style class already defined.

For example:
Code:
<STYLE>
.myStyle {
        font-size: 12px;
        }
</STYLE>

<SCRIPT>
     xxxxxx.myStyle.fontSize  //returns 12 (or 12px)
<SCRIPT>


Any ideas?


Thanks

Ben
 
try
Code:
document.styleSheets('myStylesheet').rules.item('myStyle').style.getAttribute("font-size"));

Hope that helps

Westbury

If it aint broke, redesign it!
 
Netscape gives me, document.styleSheets is not a function, IE also fails

P.S. where does 'myStylesheet' come from?
 
sorry, 'myStylesheet' should be the id of the stylesheet you are trying to read.
Code:
<style id="myStylesheet">
.myStyle {
        font-size: 12px;
        }
</STYLE>
Then use this (slightly modified from my orginal post, actually tested it instead of doing it from the top of my head) to get the property value.
Code:
document.styleSheets('myStylesheet').rules.item('myStyle').style.fontSize;

That will work in IE. I'm just esearching how to do the same thing in netscape

Westbury

If it aint broke, redesign it!
 
Thanks for that, it was a late night last night, couldn't see the obvious!!

I've had a quick look based on your code and this works in Netscape:
Code:
document.styleSheets[0].cssRules[0].style.fontSize

OK, but I really need to reference the objects by name not array index. - Still looking!


Ben.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top