The _javascript_ that's assigning the behavior to your elements is completing before the elements are in the dom.  Try putting your _javascript_ code in a function and calling that function with window.onload like this:
    <script type="text/_javascript_">
        window.>        function do() {
        var toggle = document.getElementById('toggle');
        var >        toggle. {
            onoff.style.display = 'inline';
        }
        toggle. {
            onoff.style.display = 'none';
        }
        }
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Chris Lamberson
Sent: Monday, December 05, 2005 7:58 PM
To: wsg@webstandardsgroup.org
Subject: [WSG] getElementById() always returns null

Through foresight, i already know this will be a very pitiful question to real web designers, so bear with me.

I was having some trouble finding out why, whenever I call for document.getElementById(id), it returns null (even if there is a valid id-matching element). Consider something simple, like this:


<html>
<head>
    <title>_javascript_ Testing</title>
    <style type="text/css" media="screen">
        a { font: normal 24px "Trebuchet MS"; }
        p { display: none; }
    </style>
    <script type="text/_javascript_">
        var toggle = document.getElementById('toggle');
        var >
        toggle. {
            onoff.style.display = 'inline';
        }
        toggle. {
            onoff.style.display = 'none';
        }
    </script>
</head>
<body>
    <a id="toggle" href="">Hover toggle</a>
    <p id="onoff">Hello world!</p>
</body>
</html>

Sorry I don't have a live example. The point is that the getElementById() calls for some reason appear to return null, as if they didn't find anything. Thanks, any help is appreciated!

Reply via email to