Printing Information To The Screen With JavaScript
javascript / introductionEstimated. reading time: 3 minutes, 43 seconds
As a general course of study in web development, I recommend learning HTML, CSS, PHP, then JavaScript. It’s very easy to print something to the browser window in the first three languages: in PHP, one typically uses echo, print, printf, or a similar function. You can use echo exactly where you want the information to be shown on the page:
<p><?php echo $var ?>
It’s not always clear how to accomplish the same in JavaScript. The simplest option, and the one most similar to echo, is also the least recommended: document.write
<p>It’s easy to write information to the screen <script>document.write("with JavaScript");</script>
This “inline” JavaScript is inserted exactly where you want the new information to be added. There’s also the closely related document.writeln, which adds a newline character after the insert.
Pro CSS3 Animation, Apress, 2013