HTML and CSS Reference
In-Depth Information
The <script> Tag
The <script> tag is used to include a JavaScript script in a web page in much the same
way that the <style> tag is use to add a style sheet to a page. The contents of the
<script> tag are expected to be JavaScript source code. There are a couple of other
ways to use JavaScript in your pages, too, but the <script> tag is a good place to start.
For the best results across all browsers, you should include the type attribute in the script
tag, which specifies the type of content that the tag contains. For JavaScript, use
text/javascript . HTML5 uses text/javascript as the default value for the type
attribute, but for earlier HTML versions of HTML it was required.
The Structure of a JavaScript Script
When you include any JavaScript code in an HTML document (apart from using the
<script> tag), you should also follow a few other conventions:
HTML standards prior to HTML5 required that the <script> tag be placed
between the <head> and </head> tags at the start of your document, not inside the
<body> tag. Most of the time, putting your <script> tags inside the <head> tag is
the right thing to do, but there are some cases where it makes sense to place them
elsewhere, which I'll discuss later.
Unlike HTML, which uses the <!— comment tag —> , comments inside
JavaScript code use the // symbol at the start of a line. Any line of JavaScript code
that starts with these characters will be treated as a comment and ignored.
Taking these three points into consideration, here's how the <script> tag is normally
<title> Test script </title>
<script language=”JavaScript”>
// Your JavaScript code goes here
Your Web contentgoes here
Search WWH ::

Custom Search