HTML and CSS Reference
In-Depth Information
Marking Locations with the
id
Attribute
To enable users to jump to a specifi c location within a document, you fi rst need to mark
that location. One way of doing this is to add the
id
attribute to an element at that loca-
tion in the document. Recall that the syntax of the
id
attribute is
id=”
text
”
where
text
is the name you want to assign to the id. For example, the following code
marks an
h2
element with an id of
H
:
<h2 id=”H”>H</h2>
Note that id names must be unique. If you assign the same id name to more than
one element on a Web page, browsers use the fi rst occurrence of the id name. XHTML
documents are rejected if they contain elements with duplicate ids. Id names are also
case sensitive and most browsers other than Internet Explorer differentiate between ids
named, for example,
top
and
TOP
.
Defining an Element id
• To define the id of a specific element in a Web document, use the attribute
id=”
text
”
where
text
is the value of the element id.
The Glossary page contains only a partial list of the photography terms that Gerry will
eventually add to his Web site. For now, you'll mark only sections in the glossary corre-
sponding to the letters A through F.
To add the
id
attribute to
h2
headings:
◗
1.
Scroll down the file and locate the
h2
heading for the letter A. Within the opening
<h2>
tag, insert the following attribute:
id=”A”
◗
2.
Locate the
h2
heading for the letter B and insert the following attribute in the
opening
<h2>
tag:
id=”B”
Figure 2-19 highlights the revised code.