Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: XHTML Anchors

  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    XHTML Anchors

    Hi Ive been using the following code to make anchors for my site:

    <a name="top"></a>

    Can someone please tell me an XHTML alternative to this?

    Thanks for your help.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    I don't think there are two types of anchors, one for html and other for xHTML!
    Oh.. are you asking about name attribute? You could use id there.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,928
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts
    Any element can be an anchor through the id attribute. The name attribute is deprecated for all elements except form controls. So, you could have something like:

    Code:
    <a href="#anchor">anchor</a>
    
    
    <h1 id="anchor">Headline</a>
    --or--
    <p id="anchor">Text</p>
    --or--
    <div id="anchor">Section</div>
    --or--
    <div>Lorem ipsum dolor sit amet, <a id="anchor">consectetuer</a> adipiscing elit, sed diam…</div>
    The anchor link will jump to whatever element has the appropriate ID. But note that an ID must be unique on a page. The example above is just to demonstrate the ID attribute in various situations.

  • Users who have thanked VIPStephan for this post:

    oesxyl (04-30-2008)

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    New York
    Posts
    152
    Thanks
    12
    Thanked 0 Times in 0 Posts
    If you're just looking for the XHTML-valid version of it, you've got it right there. Always make sure your attributes are enclosed in quotes and all tags are closed with the slash /...

    <br/> or <a name="..."></a>

    I use that style on my XHTML Transitional site, and it works fine with validation.


  •  

    Posting Permissions

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