It basically adds the dynamic feature of a website and turns it live. It can be used for:
- Automation: The refreshing we see on Facebook, Twitter or any social media site
The <script> Tag
It uses both the opening and the closing tag. methods and properties also play an important role here. We will further discuss all its usage in detail.
Now, let’s check the example and learn more.
Here, we have used the method as ‘getElementById()’, property as ‘innerHTML’ and DOM document. The id check of <div> tag is called in by the method inside the <script> tag to change the desired output set in HTML file.
Linking To An External File
This is the generalized example of it.
Specifically for the external file which is not stored in the same folder as the HTML file, we can use the following example:
<script src="[url_of_the_js_library]"> </script>
Illustration to code when .js file is separate:
The Js file code will be:
Before clicking the button:
Once you click on the button:
Frameworks provide codes that are already written by developers and are available to use for free. Some important and commonly used frameworks which have its library that will help you code easily are:
To learn such other HTML features subscribe to our blog!