www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons Adding JavaScript Code Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49

In this lesson we will learn about the different methods we can add JavaScript to a web page.

There are three ways by which we can place JavaScript for use in a web page. They are listed below:

1. Inside the <head> tag

2. Inside the <body> tag

3. External File

1. Inside the <head> tag
In the following example the JavaScript code has been added inside the <head> tag:

<html>
  <head>
   <script type="text/JavaScript">
    //JavaScript code goes here....
    </script>
   </head>
  <body>
  </body>
</html>

2. Inside the <body> tag
In the following example the JavaScript code has been added inside the <body> tag:

<html>
  <head>
  </head>
   <body>
     <script type="text/JavaScript">
//JavaScript code goes here....
    </script>
   </body>
</html>


3. External File
Just like CSS we can also write our JavaScript in an external text file and add its reference to our web page. The external file has to be saved with the extension .js. This method of adding JavaScript code to a web page is generally preferred.

The following example adds an external JavaScript file named ext.js in a web page:

<html>
  <head>
   <script type="text/JavaScript" src="ext.js">
   </script>
  </head>
  <body>
   </script>
  </body>
</html>

We can choose any of the above methods to include our JavaScript code in a web page. We can even use all of the above methods, simultaneously, in a single web page.

Next >>> Lesson No. 4: JavaScript Variables





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.