Studying Writing Javascript in HTML

Studying Writing Javascript code in HTML
Javascript is a programming language that operates on the browser to be written in HTML code. There are four ways of writing javascript code in HTML.

First way:
The result:
Studying Writing Javascript in HTML

Second way: Through External Files

If you do not want the Javascript code mixed with HTML, you can write it in a separate file. The trick, create a file with extension js javascript file extension, such as coding the following contents:
// file-external.js
alert ("This is the Output of an external Javascript file");
After storing the above code, we need to connect an external file with the HTML file. You do this by using the tag

The result:

Studying Writing Javascript in HTML

Not only is there a javascript onclick event on a wide range of other events, such as onsubmit, onload, ondoubleclick, onmouseover, onmouseout, and so on.

Fourth Way: Using the URL

For the last way that the writing Javascript in your URLs. This control is rarely used, but we also need to know to get to know javascript. Javascript writing the protocol URL by using Javascript. For example, try to write code like this in the browser URL.

javascript:alert(“This output From Javascript”)

The result will be executed output Javascript by the browser.
Then, How can we use this method in HTML?
This way we can use the tag  , then fill the javascript code to the attribute href . This method could replace the javascript function onclick event .
Example code :
The result:

Studying Writing Javascript in HTML

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous post Java Development Kit (JDK)
Next post Sort the array of characters in the array: PHP