Home » Online Computer Education » How to Place JavaScript in an HTML Tag

How to Place JavaScript in an HTML Tag

 
JavaScript can also be placed within HTML tags, as shown in the following example.

<BODY onLoad=document.write(“Hello World!”)> </BODY>
In this example, the JavaScript onLoad=document.write(“Hello World!”) statement has been added to the HTML <BODY> tag. This particular JavaScript statement tells the browser to write the enclosed text when the browser first loads the HTML page.

Placing small JavaScript statements inside HTML tags provides an easy way to execute small pieces of JavaScript code. Of course, this option really is beneficial only when executing small JavaScript statements and is impractical for larger JavaScript statements or situations that required multiple lines of code. However, as you will learn tomorrow, you can also trigger the execution of JavaScripts embedded in an HTML page’s head section by embedding calling statements inside HTML tags.

About

The main objective of this website is to provide quality study material to all students (from 1st to 12th class of any board) irrespective of their background as our motto is “Education for Everyone”. It is also a very good platform for teachers who want to share their valuable knowledge.

Leave a Reply

Your email address will not be published.