I was at University this week and on Tuesday our tutor game the example of using a div id to jump to a point within a page, then last night our tutor (different tutor) left us doing a hand out where they used the <a name=name here/> version. Are these both valid or should one be used over the other? Thanks
You should use the <a> its called an anchor link... Although add an ID with the name attribute <a id="ContentAnchor" name="ContentAnchor" />
The first time I saw this (and it was recently!) I thought for sure it was a mistake: <a name="messages" /> And they were using in an XHTML 1 Strict document, for page skipping. Here's what I discovered: HTML4 introduced "name" to a bunch of elements for the purpose mostly of scripting, but in this case also for inpage links. So with A, you are using "name" the way it was orinigally intended. HTML 4 added name to other things as well, such as <form>. When XHTML was created, it was indended to be HTML which would be able to be parsed through an XML parser, and ID was decided on, as there was no "name" in XML (if I've got this right). While <a name="messages" /> would be invalid for HTML4 (because of the /> ending) it's seen by an XHTML validator as <a name="messages"></a>, as an element which is empty (we put nothing in it) but isn't by spec an EMPTY element (elements which are always EMPTY such as meta, link, img, etc). "Name" was formally deprecated in XHTML1 because of the id thing and XML parser thing, but it's still sitting in the spec. It's gone for things like <form>, and is completely gone in XHTML 1.1 and 2. So, why not use either? I will likely never use the empty a for in-page reference because semantically, it's extra crap on the page. Completely valid crap. The a doesn't do anything-- it's merely a reference. So I tend to give id's to something and reference that. If you are writing XHTML it's simply a good habit not to use name for anything except form inputs (where the id and the name are both present and match entirely, to get around scripting loopholes). But you can actually do either. Adding an id as well as a name to an empty husk called <a> is doable but redundant. I first saw in-page skippies in Wikipedia (before I ever learned HTML and CSS). They use ID's it seems. I think this is leaner coding but maybe I'm biased becuase I was simply wrong about it not being valid : )