RE: JS, the DOM and CSS

by "Brett Errington" <brett(at)opensearch.com>

 Date:  Sat, 18 May 2002 23:11:00 +0800
 To:  <hwg-techniques(at)hwg.org>
 In-Reply-To:  hilma
  todo: View Thread, Original
Hi

I've never tried to access the stylesheet like this but that's probably
because I haven't had a need. Normally I access an object's (on the
page) style like so:

	document.all['object_name'].style.color

Therefore maybe you want to try something along the lines of:

	document.Sheets[0].style

If your still stuck and no one else has the answer then I shall have a
go myself. Otherwise try www.javascriptkit.com because they have lots of
useful stuff on the DOM etc.

Later,
Mr Brett
 
"That's a pain that will surely linger, and that's no lie"
- Ed Grimely
-----Original Message-----
From: owner-hwg-techniques(at)hwg.org [mailto:owner-hwg-techniques(at)hwg.org]
On Behalf Of Hilma
Sent: Saturday, 18 May 2002 6:00 PM
To: hwg-techniques(at)hwg.org
Subject: JS, the DOM and CSS

Hi -
i hope someone can help on this one - and i hope i'm in the correct
palce
for it!

I'm trying to find out, via JS, the value of particular property
within a particular class, as defined in a style sheet;
e.g. i want to know the width of anything that has class "NavButton",
(where
that
class has the width defined in a .css)

I've got as far as
mySheet = document.Sheets[0]

but when i try to access
(1)   RuleCount = document.Sheets[0].cssRules.length
or
(2)  FirstRule= document.Sheets[0].cssRules[0]
(and ultimately
(3)  NavWidth = document.Sheets[0].cssRules['NavButton'].width)

i come up with errors: "Not an object or is null".


I think i'm using the syntax from my JS book, and i want it to work in
IE6 and NS6; but cannot get further into the sheets array than
discovering that it has one element :

SheetCount = document.Sheets.length

succesfully returns 1!

Many thanks for any ideas -


h.

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA