i want someone to include a JS file of me which does something neat. I thought i put it up just like Google: you put a script tag in your source and the google js takes care of everything.
in my php file is this:
echo '<script type="text/javascript"
src="http://www.site.com/gadget.js">
</script>';
i that gadget.js, i write a span:
document.write('<span id="GadgetPicture>');
document.write('</span>');
window.setTimeout('refreshImage();', 2000);
in the refreshImage function, i want to reference my span:
document.getElementById("GadgetPicture");
But it gives me null…
Does anybody know why?
also, document.getElementById("body") also give null.
Michel
For one your missing the quote in the
<span>like everyone has said, and you should not be using the document.write to create new elements on the page as Greg said use createElement and appendElement like;You could also use jQuery and the HTML helper http://docs.jquery.com/Attributes/html#val
Also in your
setTimeoutmethod you should use it like;or
Declaring a string will cause Javascript to use
evalon the contents.You can get the body of the document with
getElementsByTagNameas the body tag is not something that usually has an ID.You can safely assume that the first found element will be the body your after, as a page with multiple would be invalid HTML.