Give me an ID not a Name

Posted on 09.01.05. Tagged with , , All

I am infinitely embarrased and the only reason I am going to share this is so you don't make the same life-long mistakes I have been making. If you 'already knew this' then great, I don't need you to make me feel even worse.

To make a link to a specific section of a page (aka Fragment Identifiers) I used to use:

<a name="gohere"></a>
<h2>New Section</h2>

and then link to it with

<a href="#gohere">Link to new section</a>

when all my life it should have been (and using the same link code)

<h2 id="gohere">New Section</h2>

The worse part is I think I vaguely remember reading this somewhere but must've forgotten. I really feel awful about making this mistake, but at the same time it is liberating that I can semantically carry on with my life. This fit of my own stupidity brought to you by Joe Clark's thoughtfully meaningful blog.

PS. I wrapped those examples with <samp> and not <code> because it is sample computer code and not useful computer code.

5 Comments

Lis
12:01 PM on 09.02.05

heh, i remember asking you how to do that, and you giving me the "wrong" version.. needless to say, i've been using that one. thanks for posting the correct code :-)

Kitta
01:34 AM on 09.04.05

Hehe, so cute Tay Tay.

I remember when you used to ask me all sorts of n00b code questions, those were the days. ;o)

Steve Clay
11:26 PM on 09.05.05

Netscape4 and probably other pre-v5 browsers required the use of named anchors, so that's where that practice came from. Best practices continue to evolve.

kevin c smith
12:44 PM on 09.06.05

Hrm...I'd say that W3Schools definition is misleading, if not downright incorrect. According to the W3C, the SAMP element is meant to mark up sample output from a program or script.

And, adding to Steve's note, this is how I'd done it to support v4 browsers:

New Section

kevin c smith
12:46 PM on 09.06.05

Oops. No preview, so I took a chance about markup/entities:

<h2><a name="gohere">New Section</a></h2>


Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?


Your email address will not be made public. Be courteous and try not to hurt my feelings.