Atlanta .NET Regular Guys

News

Brendon Schwartz - Email Me
Matt Ranlett - Email Me

Brendon Schwartz

MVP Logo
Community Kit for SharePoint
View Brendon Schwartz's profile on LinkedIn

Matt Ranlett

Matt Ranlett MVP Logo

Community Links

Useful Links

SharePoint 2007

ASP.NET 2.0

Atlanta Area Bloggers

BizTalk

SharePoint 2007 WebControls

SharePoint 2007 Development

Nested anchor links cause trouble

I was working on an web application today that was having trouble rendering correct.  The client added a link to the page and color of the text after that link would render incorrectly.  If they took the <a href></a> anchor tag out of the HTML it would render fine.  So I looked at the HTML for them and found that they had the anchor tags inside of a list and that one of the lists had not been closed properly. I thought that might be it, but No luck.  I then noticed that they were using the anchor tag like a div tag.

<a class="content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer nonummy tincidunt turpis. Cras venenatis. Vestibulum vehicula. Pellentesque quam enim, porttitor at, ultrices et, semper eget, odio. Integer quis libero. <a href="link.htm">Link Text</a>Aliquam erat justo, lobortis at, laoreet vel, commodo ac, nisl. Etiam ullamcorper viverra velit. Etiam non nibh. Etiam ut urna nec neque mollis adipiscing. Vestibulum id libero. Curabitur ornare nulla eget felis.
</a>

The problem, as you may or may not know, is that you cannot have nested anchor links.
Check it out: http://www.w3.org/TR/html4/struct/links.html#h-12.2.2

 The simple fix here is to change the outside anchor tags that are used like containers to div tags.

Here are both examples on one page
http://devcow.com/blogs/adnrg/samples/nestedanchor.htm

Comments

Dan Attis said:

Why on earth would someone think they needed nested anchor tags?  The very thought of it makes no sense.  That is a weird one.
# November 15, 2006 5:08 AM

Steven Vore said:

I'm right there with Dan - my first thought was "Why?" Did they explain what their rationale was for doing that?
# November 15, 2006 9:18 AM

Brendon Schwartz said:

The code was not written in house, so I have not idea what they were thinking.  It appears they thought that the anchor tag without an ID or href would work like a div.  No other info besides that, sorry.
# November 15, 2006 9:42 AM

Chris Wallace said:

Going off the comments and my own thoughts, this one belongs on the daily wtf.
# November 22, 2006 7:40 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)