HTML: Question about anchor tags

14 replies
I use anchor tags like this without a problem

<a name="xxxx"><!-- --></a>


However with IE 8 (Beta) they do not work.

On searching for a solution it's not clear to me if this is
a bug in IE 8 or whether the syntax I use is strictly valid.


Harvey
#anchor #html #question #tags
  • Profile picture of the author LADWebDesign
    If you are looking to see if it is valid code input your domain here:

    The W3C Markup Validation Service

    More than likely though, it's an IE 8 problem. Since it is Beta, they should have a development forum where you may post your bug.

    Linda
    {{ DiscussionBoard.errors[188594].message }}
  • Profile picture of the author clogmoney
    huh? No that's not valid.

    The name names the dom object.
    <!-- --> means a comment.

    Can you show me an example of a link which works in other browers using this style. I'm intrigued!!!
    {{ DiscussionBoard.errors[188599].message }}
  • Profile picture of the author clogmoney
    Ahh I get it now it's for anchor links on the page.

    I always just use <a name="anchor"></a> Why they put the comment tags insidethe <a> I do not know.
    {{ DiscussionBoard.errors[188777].message }}
  • Profile picture of the author clogmoney
    Haha I've said it once and I'm sure I'll say it again in my web designing life.

    I bloody hate IE!
    {{ DiscussionBoard.errors[188792].message }}
  • Profile picture of the author Paul1234
    Try <a name="xxxx">&nbsp;<!-- --></a>
    Signature

    Paul Turner

    {{ DiscussionBoard.errors[188813].message }}
    • Profile picture of the author entrepenerd
      Originally Posted by Paul1234 View Post

      Try <a name="xxxx">&nbsp;<!-- --></a>
      Yep, it looks like the issue is with the anchor not having an embedded text node. It's a known bug for now. It may get fixed later, but no guarantees.

      You should be able to use the code above to fix the issue, but probably don't even need the &nbsp; , a regular text space would probably do the trick. You just need to have some sort of text that evaluates to a text node between your opening and closing anchor tags. The comment tags you have get evaluated to their own type of node and not a regular text node.

      Hope that helps.
      {{ DiscussionBoard.errors[189186].message }}
      • Profile picture of the author Harvey Segal
        Originally Posted by LADWebDesign View Post

        If you are looking to see if it is valid code input your domain here:

        The W3C Markup Validation Service
        Yes - it is valid, thanks


        Originally Posted by entrepenerd View Post

        Yep, it looks like the issue is with the anchor not having an embedded text node. It's a known bug for now. It may get fixed later, but no guarantees.

        You should be able to use the code above to fix the issue, but probably don't even need the &nbsp; , a regular text space would probably do the trick.
        Both &nbsp and space work.

        So would it be correct to say that in theory the syntax is valid
        but it would be advisable to change it ?

        Harvey
        {{ DiscussionBoard.errors[189781].message }}
        • Profile picture of the author David Neale
          I don't think your syntax was ever "valid" per se. I'd never seen this before today.

          <a name="xxxx"><!-- --></a>

          I think you were just lucky it ever worked.

          It really was always meant to be used around text.

          <a name="xxxx">some text here</a>

          At least that's what I've always thought.

          I'd change it. I don't think it's a bug in IE 8, IE 8 is probably just using it correctly and interpreting by the "letter of the law".

          If this is so then later versions of FF, Chrome etc. will probably do the same.
          Signature

          David Neale

          {{ DiscussionBoard.errors[189846].message }}
          • Profile picture of the author Harvey Segal
            Originally Posted by David Neale View Post

            I don't think your syntax was ever "valid" per se. I'd never seen this before today.

            <a name="xxxx"><!-- --></a>

            I think you were just lucky it ever worked.
            You could be right on this


            Originally Posted by David Neale View Post

            It really was always meant to be used around text.

            <a name="xxxx">some text here</a>

            At least that's what I've always thought.
            Would &nbsp or space be regarded as text ?

            Harvey
            {{ DiscussionBoard.errors[189860].message }}
            • Profile picture of the author entrepenerd
              It's true that the intent of the named anchor was to be used to surround a group of text. But, it was standard practice years ago to use a blank anchor because some browsers would still underline the anchored text even though there was no HREF defined.

              The space and &nbsp; would still be considered text as they would both create a "text node" in the Document Object Model.

              Harvey,

              After looking at your code a little closer, a better option for you might be to use an ID attribute on the Elements that your trying to anchor to. For example, you can have:

              Code:
              <h2 id="myAnchor">Here's my text</h2>
              This will work the same as having the named anchor without the side-effect of having the text be underlined and in blue.

              The link to jump to that anchor would still be the same:

              Code:
              <a href="#myAnchor">Jump to my text</a>
              That should work perfectly for you in all modern browsers, as it's part of the HTML 4.01 spec.

              Hope that helps.
              {{ DiscussionBoard.errors[190326].message }}
  • Profile picture of the author gimmick
    IE 8 is very buggy at the moment, strange that they dare to call it Beta release... its more like a buggy test version.
    {{ DiscussionBoard.errors[190332].message }}
  • Profile picture of the author clogmoney
    entrepenerd: Good points man, I should have thought of that. Thanks for clarifying a few things for me in terms of anchor links as well!
    {{ DiscussionBoard.errors[190374].message }}

Trending Topics