How to add JavaScript
You are Here:
Adding JavaScript to Your Web Page
There are two ways of adding JavaScript to your web page. They are
- External JavaScript
- Inline (Internal) JavaScript
External JavaScript
The HTML <script> tag with src attribute is used to link JavaScript to a webpage.
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>
Inline JavaScript
The HTML <script> tag is used to add inline JavaScript to a webpage.
Example
HTML Online Editor
<!DOCTYPE html>
<html lang="en-US">
<body>
<button onclick="myFunction()">Click Me</button>
<script>
// Inline JavaScript goes here.
function myFunction(){
alert("I'm from Inline JavaScript");
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
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.