HTML - Javascript

HTML Javascript

The <script> element enables you to include script into you webpage,and just like CSS it can be included both internally and externally.

Usually, script element is kept inside the element as it is easier to locate and it executes as soon as the webpage is loaded. But it can be placed any where in the webpage.

Note-Scripts are executed as soon as it is encountered by the browser while parsing the webpage from top to bottom. So position within the wepage does matter.

What is Embedded Javascript

.Embedded javascipt is the simplest way to include javascipt into a webpage, the script to be included is simply enclosed within the <script> element in the head or body section .

The javascript code using this method affects the behaviour of elements on the same web document only.It has no effect on elements of other pages.



/* Your Javascript goes here */



<script type="text/javascript">

function Javascript_demo()
alert("Welcome to Htmltpoint!.Keep calm and carry on");

<input type="button" onclick="Javascript_demo()" value="Click here" />


What is External Javascript

The most efficient way to include javascript into your webpage is to put all the script in a single file and then link the file to your webpage.

Use the <script> element and specify the URL of the file in the src attribute.The extension of a javascript file is .js.Eg: MyScript.js

The advantage of this method is that, the code is easier to maintain and if any changes are done to the javascript file it is reflected in all the pages.

External Javascript Syntax.

<!DOCTYPE HTML>                        
	<head >
	<script src="javascript_file.js">  </script>