Datasheet
Chapter 1: Introduction to JavaScript
8
Hypertext Markup Language (HTML)
The declarative document markup language that makes up a web page interacts extensively with
JavaScript. Script allows us to make the page dynamic by writing new contents, and modifying existing
contents. You can interact with HTML by treating it as a big string and working with all the words and
symbols that make it up (as in the second example below), or by using the DOM (Document Object
Model) to manipulate the page in a hierarchical object - based way. Using HTML, you can tell the browser
to execute a block of script inline with the page using the following syntax:
< html >
< head >
< script type=”text/javascript” >
// This JavaScript block will execute first
< /script >
< /head >
< body >
< script type=”text/javascript” >
// This block will execute second
< /script >
< h1 > Hello World < /h1 >
< script type=”text/javascript” >
// This block will execute last
< /script >
< /body >
< /html >
You can also use JavaScript to generate HTML by simply writing it to the page:
< html >
< body >
< script >
document.write(“ < h1 > Hello world! < /h1 > ”);
< /script >
< /body >
< /html >
Cascading Style Sheets (CSS)
CSS describes the color, size, position, and shape of most things on a web page. CSS documents can
statically describe the look and feel of a document, but these attributes can also be changed after the
page has loaded. There is an in - depth object model available to script developers who wish to use it to
dynamically modify these attributes on the fly. By manipulating the style of an element with script, you
can animate its size or position, have it move in front of or behind other elements, or make it fade away
to nothing.
In the following example, you change the color of the document by modifying the background color CSS
attribute of the document object (it ’ s ok if you don ’ t understand this yet).
CH001.indd 8CH001.indd 8 6/25/09 7:53:17 PM6/25/09 7:53:17 PM