HTML and CSS Reference
In-Depth Information
12.3. JavaScript
All the executable content elements we've discussed so far have had one
common trait: they are separate from the browser and the HTML/XHTML
documentseparate data, separate execution engine.
JavaScript is different. It is a scripting language that taps the native
functionality of the browser. You may sprinkle JavaScript statements
throughout your documents, either as blocks of code or as single state-
ments attached to individual tags. JavaScript-enabled browsers, includ-
ing all the currently popular ones, interpret and act upon the JavaScript
statements you provide to do such things as alter the appearance of the
document, control the display, validate and manipulate form elements,
and perform general computational tasks.
As with Java, we do not pretend to teach JavaScript programming in
this topic. We'll show you how to embed and execute JavaScript within
your documents, but we ask that you turn to topics like the companion
JavaScript: The Definitive Guide (O'Reilly) for a complete reference.
12.3.1. The <script> Tag
One way to place JavaScript code in your document is via the HTML and
XHTML standard <script> tag.
The browser processes everything between <script> and </script> as
executable JavaScript statements and data. You cannot place HTML or
XHTML within this tag; the browser flags it as an error.
However, browsers that do not support <script> process its contents as
regular HTML, to the confusion of the user. For this reason, we recom-
mend that you include the contents of the <script> tag inside HTML com-
ments, just like CSS <style> rules:
<script language="JavaScript">
JavaScript statements go here
Search WWH ::

Custom Search