HTML & CSS
Can you add the alt attribute to the anchor <a> tag?
(I know alt is normally used with the <img> tag...)
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.
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...)
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.
You're really smart!
Seriously, I asked a legitimate question, but some people like to be ******
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.
The title attribute is part of <a> so it's fine to use it.