document.write()
Most JavaScript
tutorials start with similar examples. This is probably because these types of scripts
quickly produce results. At the risk of looking like a copycat, I'll follow my
predecessors and demonstrate some simple JavaScript methods.
<script language="Javascript">
document.write("This is JavaScript")
</script> |
The document.write() method is used to write to text
or HTML to the document. |
The browser reads
HTML markup from top to bottom when a page is loaded. When the JavaScript tag was reached,
the browser recognized the document.write() method, wrote the message and continued
on. You can make it more interesting by adding some HTML tags within document.write().
<script language="Javascript">
document.write("<center><e><h2>This is
JavaScript</h2></e></center>")
</script> |
Dialog Boxes. JavaScript and a corresponding HTML reference
The examples above, demonstrate the construction of functions, function name(){ statements }. The
functions were called by the JavaScript event handler onClick.
They utilized the document object methods alert(),
confirm & prompt()
to generate a response.
|