SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    alt for <a> tag??

    Can you add the alt attribute to the anchor <a> tag?

    (I know alt is normally used with the <img> tag...)


    Debbie

  2. #2
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xhtmlcoder View Post
    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...)

    Thanks,


    Debbie

  4. #4
    Non-Member
    Join Date
    Jun 2012
    Posts
    88
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    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".


    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

    1. Does it do what I want in the browsers I need to support?
    2. 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.

  5. #5
    SitePoint Guru bronze trophy TheRaptor's Avatar
    Join Date
    Jul 2011
    Location
    New York
    Posts
    710
    Mentioned
    40 Post(s)
    Tagged
    0 Thread(s)
    TheRaptor - Joe

  6. #6
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TheRaptor View Post
    You're really smart!

    Seriously, I asked a legitimate question, but some people like to be ******


    Debbie

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,200
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    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.

    Quote Originally Posted by DoubleDee View Post
    I asked a legitimate question
    ... and he was pointing out that it has been asked and answered many times before.

  8. #8
    SitePoint Zealot
    Join Date
    Apr 2003
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The title attribute is part of <a> so it's fine to use it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •