trouble with loading a script to a document using javascript
Hi I am new to javascript and having trouble with it. It only works when I use window.onload. If i try to write a script and use document.write("blahblah"); the document shows up blank. What could be the issue here?
p.s. someone else recommended that i try using window.onload function() {document.write("blahblah")}
and it worked but i can't write scripts normally without it.
can someone please explain why?
document.write is considered to be a bad practice.
For example, when executed after the page has finished loading it will overwrite the page, or write a new page, or not work at all.
The solution may be to use innerHTML method of a DOM element, something like this:
<html>
<div id="block"></div>
<script>
document.getElementById('block').innerHTML = '<b>YO</b>, that works!';
</script>
Bookmarks