JavaScript How to


The HTML <script> tag is used to insert a JavaScript into an HTML page.

Writing to the HTML Document
The example below writes a <p> element with current date information to the HTML document by using (i) the method write of the object document and (ii) the date function/object, which gives the current time.

     


To insert a JavaScript into an HTML page, use the <script> tag. Inside the <script> tag, use the type attribute to define the scripting language. The <script type="text/javascript"> and </script> tells where the JavaScript starts & ends and are executed by the browser.

Changing HTML Elements
The example below writes the current date into an existing <p> element. To manipulate HTML elements, the example uses
     



Demonstration
The following demonstration shows how the script of HTML and JavaScript is displayed on the Web.

     





      I asked God for a bike, but I know God doesn’t work that way.    
      So I stole a bike and asked for forgiveness.