|
-
Sep 10th, 2005, 10:02 AM
#1
[RESOLVED] document.getElemendById() always returns null
Why does the following piece of code *always* return null?
I cannot figure this out...
Code:
<body>
<div>
<script language=javascript>
alert(document.getElementById("p"));
</script>
<div id="p" style="WIDTH: 600px; HEIGHT: 450px"> </div>
</div>
</body>
- ØØ -
-
Sep 10th, 2005, 10:45 AM
#2
Re: document.getElemendById() always returns null
The getElementById function will only return the id's of elements already rendered. Put it underneath and it will work:
HTML Code:
<body>
<div>
<div id="p" style="WIDTH: 600px; HEIGHT: 450px"> </div>
<script type="text/javascript">
alert(document.getElementById("p"));
</script>
</div>
</body>
-
Sep 10th, 2005, 12:43 PM
#3
Re: document.getElemendById() always returns null
Thanks a lot. Not me needing it though. But I rated you anyway...
- ØØ -
-
Sep 11th, 2005, 09:39 PM
#4
Re: document.getElemendById() always returns null
 Originally Posted by visualAd
The getElementById function will only return the id's of elements already rendered. Put it underneath and it will work:
HTML Code:
<body>
<div>
<div id="p" style="WIDTH: 600px; HEIGHT: 450px"> </div>
<script type="text/javascript">
alert(document.getElementById("p"));
</script>
</div>
</body>
ok..
Adam, what if the code of getElementyById is in the head section of the code?
See, I have an instance where I focus the next element (which is rendered above/before the current element) by using getElementById to access it, the problem it seems is that it cannot find that element.
Does getElementById work for those elements which are rendered next/below the current element?
Somehow, that seems to be the case in IE.
What's the difference with accessing elements via Name and accessing elements via ID?
-
Sep 11th, 2005, 09:39 PM
#5
Re: document.getElemendById() always returns null
I'm just gonna make a new thread for this.
-
Sep 11th, 2005, 11:29 PM
#6
Re: document.getElemendById() always returns null
nevermind, it was a bug in my code afterall. the function getElementById works fine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|