View Full Version : <a> tag with no href attribute is valid XHTML!?
STDestiny
09-06-2003, 04:50 AM
This is really wierd, and maybe someone has an explanation, but I wasn't under the impression that
<a onclick="javascript:function()"> (or mouseover/mouseout, etc)
was valid XHTML (see http://validator.w3.org/check?uri=http%3A%2F%2Fwww.startrekdestiny.us%2Fhtml%2Fframes%2Fright.php )
(The actual page is the right frame of what loads after the preload script at http://www.startrekdestiny.us/html/preload.php
if you load it, beware that the site is graphic intensive)
Anybody have an idea?
-Andrew
MotherNatrsSon
09-06-2003, 05:04 AM
My guess is that it is because you have a transitional doctype and not strict. Change it to a strict doctype and then see what happens.
MNS
STDestiny
09-06-2003, 05:20 AM
Wierd, I have the doctype set in the file as strict. Maybe the validator cached an earlier version (I have been using it a lot)
If you try validating it on my local machine server, (which should be the same file) http://stdestiny.no-ip.org/html/frames/right.php
That comes up as validating as XHTML strict.
-Andrew
MotherNatrsSon
09-06-2003, 05:40 AM
I tried that one and it did come up as validating "strict". The first one did not. I looked at the xhtml 1.0 specs and found nothing on the a tag at all. It must "think" it is an anchor or something. Maybe a glich. One of the "coding gods" may come along and knw why.
I did find this in the html 4.01 spec:
Authors may also create an A element that specifies no anchors, i.e., that doesn't specify href, name, or id. Values for these attributes may be set at a later time through scripts.
http://www.w3.org/TR/html40/struct/links.html#edef-A
Maybe that is why??
MNS
oracleguy
09-06-2003, 06:45 AM
You don't need to specify a href because if you only specify a name, it isn't a link, it becomes for lack of a better word a bookmark.
So you can then do mypage.htm#blah, I'm sure you've seen this before. It justs goes down to the anchor on page load.
It is giving you the benifit of the doubt in validating the code because as MNS posted you can set the attributes on the fly.
STDestiny
09-06-2003, 02:16 PM
I guess that makes sense,, and not using an href or anything has actually helped me some reason, the script wouldn't work as a href="javascript:function()">, only as onclick)
MNS, I didn't look for the specs, but here's the <a> tag info from the actual DTD (I just looked it up)
[code]
<!ELEMENT a %a.content;>
<!ATTLIST a
%attrs;
%focus;
charset %Charset; #IMPLIED
type %ContentType; #IMPLIED
name NMTOKEN #IMPLIED
href %URI; #IMPLIED
hreflang %LanguageCode; #IMPLIED
rel %LinkTypes; #IMPLIED
rev %LinkTypes; #IMPLIED
shape %Shape; "rect"
coords %Coords; #IMPLIED
>
[/code
#IMPLIED seems to mean that there is no specific value for the attribute (which makes sense, since llinks can be anything) and that it's not required (That's what #REQUIRED is used for.)
-Andrew
<edit>One thing I noticed about it though. Since there's no href, no browser I've tried (IE6, Moz1.5b, Opera 7) changes the cursor to the "hand" like they normally do with links. (which might not be a problem, since I think a lot of people respond to mouseovers as links anyway)
This may be one way to use mouseovers without actually linking to any page.)</edit>
liorean
09-06-2003, 02:37 PM
An a tag without a href isn't a link, and an a tag without an id (or name for <1.1) isn't an anchor (possible target element, or 'resource' to use the XLink terminology). In that case the a tag acts just like any inline tag without any specific behavior or associated styling, just like a span tag would, except that the span may contain a tags.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.