Book Image

Object-Oriented JavaScript

By : Stoyan Stefanov, Stoyan STEFANOV
Book Image

Object-Oriented JavaScript

By: Stoyan Stefanov, Stoyan STEFANOV

Overview of this book

Table of Contents (18 chapters)
Object-Oriented JavaScript
About the Author
About the Reviewers
Built-in Functions
Regular Expressions

Including JavaScript in an HTML Page

In order to include JavaScript in an HTML page, you need to use the <script> tag:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    <title>JS test</title>
    <script type="text/javascript" src="somefile.js"></script>
    <script type="text/javascript"> 
       var a = 1;

In this example, the first <script> tag includes an external file, somefile.js, which contains JavaScript code. The second <script> tag includes the JavaScript code directly in the HTML code of the page. In both cases, the <script> tag takes a type attribute, which is required in XHTML 1.0, although the code will work even without it. The browser executes the JavaScript in the sequence it finds it in the page. This means that if you define...