HTML Functionality using JavaScript

You are Here:

Adding JavaScript to HTML

There are two ways of adding JavaScript to your HTML. They are

  • External JavaScript
  • Internal JavaScript

External JavaScript

Use <script> tag with src attribute to link JavaScript to an HTML document.

Note: The external JavaScript file used in this example is alert-me.js

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <button onclick="myFunction()">Click Me</button> <script src="/script/alert-me.js"></script> </body> </html>

Internal JavaScript

The HTML <script> tag is used to add internal JavaScript to an HTML document.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <button onclick="myFunction()">Click Me</button> <script> // Internal JavaScript goes here. function myFunction(){ alert("I'm from Internal JavaScript"); } </script> </body> </html>

Reminder

Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in HTML.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author