Forum Moderators: open

Message Too Old, No Replies

Anchor Naming Convention

A name="%%", A id="%%", or both?

         

MrMcTerse

6:43 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



[lists.w3.org...]

The above is from lists.w3.org, and is dated back in 1999.

I take this to mean the following:

<a name="foo" id="foo" href="#">bar</a>

My question is, does this convention apply in today's standards of development, or is enough to simply use the method below:

<a id="foo" href="#">foobar</a>

The line of reasoning is that the older user agents referred to in the article must certainly be out of existence by now, and more standards compliant browsers, at least to this standard, anyway, must by now be the norm. Can we drop the 'name='?

rogerdp

7:05 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



Yes, you can drop the name attribute. Futhermore, every element can have an id attribute, so you're not limited to <a>

I.e.:

<a href="#woot">What did the snail riding on the back of the turtle say?</a>

<h2 id="woot">Wheeeeeee!</h2>

MrMcTerse

11:08 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



Well that's good to learn. I had the understanding that everything was leaning toward containerization, so the identification of containers follows.

Thanks, Roger, for the quick reply.

Now if I could just get this darn thing to work, :-)

ergophobe

6:10 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Futhermore, every element can have an id attribute, so you're not limited to <a>

If I'm not mistaken, though, with somewhat worse support than <a id="woot"> or am I misremembering. Or is support good enough in all modern browsers?

pageoneresults

6:26 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The name attribute is deprecated in HTML 4.01 Strict and above so you won't be able to use it. I've had no problems using id in place of name. Just need to be careful that you don't end up with more than one id per page (with same name) as it is not valid markup.

ergophobe

6:30 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure whether your answering my question or the one before. That wasn't exactly my question though.

I know that name has been deprecated (except in form fields of course), but what I was wondering is how good the support is for using id in non-anchor tags as fragment identifiers.

I seem to remember trying it not so long ago and finding some browsers that didn't work. I can't remember, though, if I was trying to support NS4.x on those pages or not.

Tom

rogerdp

9:58 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



Unless you expect a lot of NN4 visitors for some reason, using id should be fine. (I didn't check if NN4 supports id for fragment identifiers.) The worst that happens is they are at the top of the page.

ergophobe

10:28 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually, the worst that happens is that nothing happens. In other words, it's not such a problem for people coming to a page and then being dropped at the top, but it is bad when internal navigation links within a page don't work.

As for my previous comment, I may be misremembering too.

Mohamed_E

1:25 am on Mar 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The name attribute is deprecated in HTML 4.01 Strict and above so you won't be able to use it.

I may be missing the point, but that does not seem to fit in with my experience. I use

<a name="tag">
extensively and none of the validators complain about it. The following test file validated to 4.01 Strict with Tidy, W3C and WDG validators:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/REC-html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test of named anchor</title>
</head>

<body>
<H1>Main Header</H1>

<H2>Table of contents</H2>
<UL>
<LI> <A HREF="#tag">The second level header</A>
</UL>

<H2>[b]<A NAME="tag"></A>[/b]Second level header</H2>

<P>Some text.
</body>
</html>

pageoneresults

2:33 am on Mar 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I may be missing the point, but that does not seem to fit in with my experience.

You are correct, my mistake. I've been working mostly in XHTML 1.1 so I'm up against a slightly different set of deprecated elements with the name attribute being one of them.

<div><a name="example">Named Anchor</a></div>

So, my above statement only applies to XHMTL 1.1...

Changes from XHTML 1.0 Strict [w3.org]

<edit>Corrected grammer.

[edited by: pageoneresults at 3:46 am (utc) on Mar. 12, 2004]

Mohamed_E

3:27 am on Mar 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, my above statement only applies to XHMTL 1.1...

Since I am thinking of maybe going to XHTML one day this is very valuable info, thanks!

I never knew, until this thread, that it was possible to use

<h2 id="woot">Wheeeeeee!</h2>
as a target, so I have already learned a lot already from this thread.

So much knowledge out there :) ; so little brain in which to store it :( .

Mohamed_E

3:22 pm on Mar 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Netscape 4.8 seems unable to accept anything but
<A NAME="tag"></A>
. It seems to recognize neither
<A id="tag"></A>
nor
<h3 id="tag">
.