Link External JavaScript File

Link External JavaScript File

Link External JavaScript File

Link External JavaScript File. Coding your JavaScript ins your HTML file is messy . That will make things very hard to debug, difficult to trace , basically make your life freaking hard when building your Site.

In this Article we will step into how to link an External JavaScript file into your HTML fie.

I found this site quite useful as a reference when you encounter any problem about JavaScript.

Follow the Step by step below on how to Link External JavaScript File

In this Article my focus is to show how to  link your JavaScript file  to the HTML , using the Sample code below. Code wise i will not explain how it works. If you are really interested to know how the code work check out here

    1. Create  a Folder name JavaScript inside the root folder where your HTML file located.
    2. This Folder will store all the necessary JavaScript File that your HTML Site need to reference.
HTML Root Folder
HTML Root Folder
    1. Create a JavaScript file“.js” and save it into the folder that you have just created
         function myFisrstScript(){
                 
                var setText=document.getElementById("fillText");
                 setText.textContent="I am Flling in atext via Javascript"
               /*  var text = div.textContent*/
                 
                 
             }
 
        
    1. Open the HTML File and embed the Code showed below into your header

        <script type ="text/javascript" src ="javascript/Untitled.js" ></script>

       
    1. Your Final Code should be as below
        <!DOCTYPE html>
        <html>
        <head>
        <script type ="text/javascript" src ="javascript/Untitled.js" ></script>
       </head>
           <p>Fill in the Text using Javascript</p>
           <div class="fillText"> </div>

        <body>
        
        
            
       </body>

       </html>       


        

 

Leave a Reply

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

eleven + 2 =