...

View Full Version : XHTML Anchors



CurtWRC
04-30-2008, 12:47 PM
Hi Ive been using the following code to make anchors for my site:

<a name="top"></a>

Can someone please tell me an XHTML alternative to this?

Thanks for your help.

abduraooft
04-30-2008, 01:18 PM
I don't think there are two types of anchors, one for html and other for xHTML!
Oh.. are you asking about name attribute? You could use id there.

VIPStephan
04-30-2008, 02:24 PM
Any element can be an anchor through the id attribute. The name attribute is deprecated for all elements except form controls. So, you could have something like:



<a href="#anchor">anchor</a>


<h1 id="anchor">Headline</a>
--or--
<p id="anchor">Text</p>
--or--
<div id="anchor">Section</div>
--or--
<div>Lorem ipsum dolor sit amet, <a id="anchor">consectetuer</a> adipiscing elit, sed diam…</div>


The anchor link will jump to whatever element has the appropriate ID. But note that an ID must be unique on a page. The example above is just to demonstrate the ID attribute in various situations.

Ricky158
04-30-2008, 05:28 PM
If you're just looking for the XHTML-valid version of it, you've got it right there. Always make sure your attributes are enclosed in quotes and all tags are closed with the slash /...

<br/> or <a name="..."></a>

I use that style on my XHTML Transitional site, and it works fine with validation.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum