doubledee — 2012-06-29T14:05:01-04:00 — #1
Can you add the alt attribute to the anchor <a> tag?
(I know alt is normally used with the <img> tag...)
xhtmlcoder — 2012-06-29T14:36:42-04:00 — #2
The alt attribute is defined in a set of tags (namely, IMG, AREA and optionally for INPUT and APPLET) to allow you to provide a "text equivalent" for the object in other words the answer being: no you cannot apply it to the A element.
doubledee — 2012-06-29T14:49:27-04:00 — #3
My brain isn't working today!!
What I was trying to do is this...
Under my Comments section, I have an icon for editing a Comment and next to it is a hyperlink Edit. I have the TITLE attribute defined for the image so when you hover over the icon, you see "Edit Comment".
Since the <a> wraps both the text and the icon, I thought it would be nice if you would see "Edit Comment" whether you hover over the hyperlink OR the icon.
So my original question should have said, "Can you place the TITLE attribute in the anchor <a> tag??"
(My suspicion is that you will again say no...)
theraptor — 2012-06-29T16:07:02-04:00 — #4
system — 2012-06-29T20:32:15-04:00 — #5
Isn't the obvious answer "You can put whatever you like in any tag."
Did it work when you tried putting a title attrib. in the anchor?
The only questions then are
- Does it do what I want in the browsers I need to support?
- Do I care if my HTML is valid or not?
If the answer to 2 is yes and your html is invalid, then you will need to find another way to do what you want.
TheRaptor's posted link will help you answer the above 2 Q's as well.
doubledee — 2012-06-29T22:04:11-04:00 — #6
You're really smart!
Seriously, I asked a legitimate question, but some people like to be ******
ralphm — 2012-06-30T04:02:56-04:00 — #7
Alt is for images. Really, since you are using text there, the text should just say what the link is for. E.g. "Edit Comment" ... (or, if that's too long, maybe have "Edit" and then a title on the text).
Anyhow, since you have text, I would recommend you not use an image in the HTML but set it as a background image to the text, as it's just decoration. A person using a screen reader will otherwise have the image alt read out to them, then the link text and so on ... which is a bit redundant.
... and he was pointing out that it has been asked and answered many times before.
caimin — 2012-07-03T01:24:19-04:00 — #8
The title attribute is part of <a> so it's fine to use it.