JavaScript are useful in making HTML pages to be more interactive and dynamic.
The HTML <script> Tag
The <script> tag is useful in defining a client-side script (JavaScript).
The <script> element is capable of containing scripting statements, or it refers or points to an external script file by using the src attribute.
Some of the common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
This JavaScript example explains how to write "Hello JavaScript!" into an HTML element with id="demo":
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
Try it Yourself
Tip: You can study more about JavaScript by going through our JavaScript Tutorial.
A Taste of JavaScript
Below are few examples to show what JavaScript can do:
document.getElementById("demo").innerHTML = "Hello JavaScript!";
Example
document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "red";
Example
document.getElementById("image").src = "picture.gif";
The HTML <noscript> Tag
The <noscript> tag is used for providing an alternate content for users who had disabled scripts in their browser or having a browser which does not support client-side scripts:
Example
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
Try it Yourself
HTML Script Tags
Tag | Description |
---|---|
<script> | It is used to define a client-side script |
<noscript> | It is used to define an alternate content for users who do not have support client-side scripts in their browsers |