HTML and CSS Reference
In-Depth Information
JavaScript is also very useful for listening for events such as mouse clicks and key presses on the keyboard. Using
what are known as event listeners, a JavaScript developer can specify some code that should be executed when an
event occurs. Remember when you looked at the <button> element in Chapter 5 and I said that to make “dumb”
buttons smart, you had to use JavaScript? Well, this is how it is done.
An advantage that JavaScript has over other languages is that it runs directly in the user's web browser. This means
that the code will often execute very fast. It also helps to lighten the load on the web server that already has enough
to deal with, responding to page requests from other users.
Here are some demos of what can now be done using JavaScript and HTML5. Take a look at them—and enjoy:
These demos take advantage of some really advanced HTML5 technologies that are not yet supported in all
browsers. I recommend that you view these demos in Google Chrome to ensure that they will work correctly.
The Wilderness Downtown by Google— http://www.thewildernessdown
town.com/
Water/Ocean by OutsideOfSociety http://oos.moxiecode.com/js_webgl/
water_noise/
Rome by Google http://www.ro.me/
JavaScript Terminology
Throughout this chapter you may encounter some terminology that is new to you. So that you understand what is
going on, here are some key terms.
variable —Variables allow you to store pieces of data so that you can use them in your programs. You will
look at variables in more detail later in this chapter. The following example creates a variable called age and
stores in it the integer value 20 .
var age = 20;
function —A function consists of a block of JavaScript code that is executed when the function is called . You
call a function by adding the function name to your code at the position which you want the code within the
function block to be executed. The following example shows a simple function called printName .
function printName() {
document.write(“Matt West”);
}
You will learn about functions in more detail later in this chapter.
object —A JavaScript object consists of a collection of properties and functions. Each of these properties
stores some data about the object. A person object, for example, might have properties such as name ,
height , age , and weight . This concept is similar to the concept of microdata items described in Chapter 8.
JavaScript objects can also have functions attached to them. Every web browser has a document object that
has a number of properties containing information about the page. This document object also has a number
of functions attached to it. These functions are called on an object using the object.function() syntax.
Search WWH ::




Custom Search