getElementById driving me crazy

P

pantagruel

the browser is firefox

the javascript:

function slideshowchecker(){

if(document.getElementById){alert('it works');}
slide = document.getElementById("slideX");



if(slide==null){
alert('yes2');
}

}
window.onload=slideshowchecker();

the document has a div id = slideX.
both alerts keep coming up.

here is the html

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>slideshow</title><script

src="jscripts/GTA.js" ></head><body><div class="slide" id="slideX">
grrrrrrrr

</div></body></html>

Why is slideX coming up null?

I'm really tired, I've been working from noon to 9 pm yesterday and
from 1 am to 5 am this morning.
 
P

pantagruel

On May 13, 5:40 am, pantag
oh wait, just realized, the script is executing before the div exists
so slide is null.
 
L

-Lost

window.onload = slideshowchecker;

Don't use the call operator, when assigning functions to events.

If you need to pass the event:

window.onload = function(e) { alert('on' + e.type); }

If you need to pass arguments:

window.onload = function()
{
func1('arg1', 'arg2');
}

On May 13, 5:40 am, pantag
oh wait, just realized, the script is executing before the div exists
so slide is null.

What is "GTA.js?" I ask only because I am a Grand Theft Auto fanatic.
If it has something to do with that, you must share. :)
 
P

pantagruel

Thanks for the help, no actually it isn't Grand Theft Auto, sorry.
Hmm, maybe I should reconsider my acronym.

Cheers,
Bryan Rasmussen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top