Quote:
Originally Posted by iBall
<offTopic style="Tip">
In that case using document.write() is fine for this purpose to help students quickly get output to the browser while learning the basics of javascript.
As soon as you start learning more about the Document Object Model (DOM), you really should then use more appropriate DOM methods to output to the browser.
document.write outputs to the current page only while it is still loading. If called after the the page has loaded, it will output to a new page. document.write is really only useful for writing to child pages.
</offTopic>
|
Using innerHTML is far more straightforward and less error prone for beginners to use than document.write is - there's no reason for using the more complicated document.write rather than innerHTML except in those advanced userscripts where document.write is the only way that works.
There are far fewer situations where innerHTML will break the web page functionality compared to the ways that document.write can break the functionality.
Of course the way that always works is to use the proper DOM commands that make up about 60% of JavaScript but learning those is a bit more complex and since innerHTML will work most of the time it is the obvious choice for beginners to use first.