HTML Script
To include client side script in HTML documents, <script>
tag can be used. Client side scripts brings in the dynamic flavor to static HTML pages. JavaScript is the most popular client side language.
HTML Script Tag
Using HTML script tag client side scripts can be included. Script can be included in two ways, either the script code itself can be enclosed within the <script>
tag in the HTML page itself or using src
attribute an external script file can be included.
Very common use case for including script in client side is form validation and dynamic change in display elements. Following is an example.
<!DOCTYPE html> <html> <head> <title>HTML Meta Tag Example</title>
<script type="text/javascript" src="/js/script.js"></script>
<script type="text/javascript"> function helloScript(){ alert("Hello, World"); } </script>
</head>
<body> <p>Click button to say hello!</p> <input type="button" onclick="helloScript();" name="hello" value="hello" /> </body>
</html>
Example Output
Click button to say hello!
In the above example, we have included script code in HTML head within the <script>
tag. Then we have also included an external file using src
attribute.
HTML noscript Tag
Users can disable the support in web browsers for rendering scripts like JavaScript. On encountering such situation <noscript> tag will be executed. This noscript tag can contain any HTML elements. It will be executed and not other processing will be done when the browser does not support scripts or if it is disabled.
<head>
<script type="text/javascript">
function helloScript(){
alert("Hello, World");
}
</script>
<noscript>Your browser does not support JavaScript!</noscript>
</head>
Some More JavaScript Examples
<script>
document.getElementById("hello").innerHTML = "Hello World!";
</script>
<script>
document.getElementById("hello").style.fontSize = "12px";
</script>