HTML and CSS Reference
In-Depth Information
the quotes around the argument to alert are single quotes, unlike the
double quotes used in the previous example. In JavaScript, you can
use either single or double quotes—it doesn't make any difference as
long as you start and end a given string with the same type of quote.
But double quotes are used in the HTML for the attribute value, so
using double quotes in the JavaScript would make the HTML invalid.
All three approaches for including JavaScript in a web page that you've seen
in this section use the Document Object Model (DOM) to cause things to
happen within the page. The next section looks at the DOM more closely.
The Document Object Model (usually referred to as the DOM ) is the
way you access a web page through JavaScript. As the name implies,
it's based on an object called window . You already used the alert method
of the window object in the previous section. The window object contains
properties and methods provided by the browser, the most important
of which is the document object. The document object contains properties
and methods provided by the web page. To experiment with the docu-
ment object, create a simple web page:
<!DOCTYPE html>
<meta charset="utf-8">
<title>DOM Example</title>
<div id="first">
<h1>First div</h1>
<p>Paragraph in
first div</p>
<div id="second">
<h1>Second div</h1>
Search WWH ::

Custom Search