Skip to main content

Use external JavaScript file

Hi people who are interest to learn js.
 So this is the second simple tutorial and this will be very short and sweet one that describes about how to prevent using js within HTML tags. That means in this tutorial  will show you how to use external js file.
Actually there is nothing new. So let’s move on.
If you see my first js tutorial you know that we wrote our js programs within HTML tags. So there is another solution to make our life easy.
Lol…👻😂
Let’s start...
Ok let’s take our last example that called js function by clicking a button in the webpage.
See here…


                                                  Figure 1


                              Figure 2

To achieve this you have to write your js code in separate file and save it as name.js (look the way that I have saved my file (one.js)). Then write your html code separately. After that you can import your js file by adding the path of your js file.
<script language="javascript" src="one.js" type="text/javascript">
</script>

So ……… that’s all about using external js file and I invite you to try with different examples.
Thank you.

PS:
Other thing, if you can’t run js in your web browser, that means you have not enable js in your web browser. So first enable it and try the examples.
As an example I’ll show how to enable js in chrome.
Step 1


Step 2


Step 3

Step 4


If you have any concern about enabling js in any other web browser comment below.
Thank you again.🙋

Comments