Search within TutorialsPark

HTML Javascript Intro


While HTML and CSS control structure and style respectively. Javascript controls the behaviour.


The script element.

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

2.Usually, script element is kept inside the <head> 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.

Embedded Javascript

1.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 .

2.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.

Example : Embedded Javascript

Give it a TRY! » Note-The type attribute is used to declare the script type. If nothing is declared browser assumes it as javascript.


External Javascript.

1.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.

2.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

3.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.

Note- External javascript file is stored in browsers cache(temporary) memory once loaded,thus speeding up page load time.

HTML <noscript> Element

1.The element <noscript> is used to display content(usually text) to users who have disabled javascript or who's browser lacks support for it.

2.The true purpose of <noscript> element is to let the user know that the browser javascript is disabled or no support is available.

Example: Javascript <noscript> element

Give it a TRY! »


Peep into Javascript

1.Javascript to write text directly to your webpage.

Give it a TRY! »


2.Javascript to create pop up alert boxes

Give it a TRY! »


3.Javascript to display the current time.

Give it a TRY! »