Fire-House 58

My first JavaScript

first

b-2


JavaScript:  
firehouse58.com  

 

Hard Reload
To See Menu

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

JavaScript HTML

<script language="Javascript">
function alert_(){
alert("This is JavaScript !!")}
</script>

<input type="button" value="Try it!"  onClick="alert_()">

  alert()

<script language="Javascript">
function confirm_(){
confirm("You are learning JavaScript !!")}
</script>

<input type="button" value="Try it!"  onClick="confirm_()">

  confirm()

<script language="Javascript">
function prompt_(){
prompt("What is your favorite color?")}
</script>

<input type="button" value="Try it!"  onClick="prompt_()">

  prompt()

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.


[back]   [home]   [next]