Re: Modifying stylesheet properties through JS
by Andrew McFarland <aamcf(at)aamcf.co.uk>
|
Date: |
Wed, 15 Jan 2003 20:38:20 +0000 |
To: |
hwg-languages(at)hwg.org |
References: |
|
|
todo: View
Thread,
Original
|
|
At 16:16 15/01/03 +0000, Rajnish Bhaskar wrote:
>I'm finding this very frustrating, because that's not working. It
>looks like it should be working, but it's not. The Javascript
>console in Mozilla tells me that "document.getElementById("first")
>has no properties" and IE tells me "object expected". If you want to
>see the page, you can find it at
>http://elit2003.com/elit/elit2003/interested.html
This was a good one. It had me scratching my head for a while.
The first problem is that you have several elements with the same id - this
is not allowed, and was probably causing odd problems.
The main problem was the JavaScript that altered the properties of the
element was being called before that element had been read; essentially the
element didn't exist at the time you tried to change it.
The solution is quite easy: wrap the javascript in a function and call that
function in an onload for the body. That way the javascript isn't called
until the element is there.
See http://aamcf.co.uk/temp/interested.html for a fixed version. Watch out
for the <base> element I added to the head.
Andrew
--
http://aamcf.co.uk/
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA