ptg16476052
108 LESSON 6: Working with Links
You’ll need to add an ID to the section heading for Byrd. You then can link to that ID
from the See Also instances in the file for M.
You can choose any ID you want for the element, but each ID in the page must be
unique. (If you have two elements with the ID fred in the same page, how would the
browser know which one to choose when a link to that ID is selected?) A good, unique
ID for this example is simply byrd because byrd can appear only one place in the file,
and this is it. Adding the ID is as simple as adding the id attribute to your <h2> element:
<h2 id="byrd">Byrd, William, 1543-1623</h2>
So, you’ve added your ID to the heading and its name i s "byrd". Now go back to the See
Also line in your m.html file :
<p><em>See Also</em>
Byrd, Gibbons, Lassus, Monteverdi, Morley, Weelkes, Wilbye</p>
You’re going to create your link here around the word Byrd, just as you would for any
other link. But what’s the URL? As you learned previously, pathnames to anchors look
similar to the following:
page_name#anchor_name
If you’re creating a link to the b.html page itself, the href is as follows:
<a href="b.html">
Because you’re linking to a section inside that page, add the anchor name to link that sec-
tion so that it looks like this:
<a href="b.html#byrd">
Note the small b in byrd. Anchor names and links are case sensitive; if you put #Byrd in
your href, the link might not work properly. Make sure that the anchor name you use in
the name attribute and the anchor name in the link after the # are identical.
▼
A common mistake is to put a hash sign in both the anchor name
and the link to that anchor. You use the hash sign only to sepa-
rate the page and the anchor in the link. Anchor names should
never have hash signs in them.
CAUTION
So, with the new link to the new section, the See Also line looks like this:
<p><em>See Also</em>
<a href="b.html#byrd">Byrd</a>,
▼ Gibbons, Lassus, Monteverdi, Morley, Weelkes, Wilbye</p>