As described in @ j08691, nested a elements are not allowed in the HTML syntax. HTML specifications do not say why; they simply emphasize the rule.
On the practical side, browsers effectively apply this restriction in their parsing rules, so, unlike many other problems, a specification violation just doesn't work. Parsers efficiently process the start tag <a> inside the open element a , as an implicit end to the open element before starting a new one.
So, if you write <a href=foo>foo <a href=bar>bar</a> zap</a> , you will not get any nested elements. Browsers will parse it as <a href=foo>foo</a> <a href=bar>bar</a> zap , i.e. Like two consecutive links followed by some plain text.
There is nothing inherently illogical with nested a elements: they can be implemented, so clicking on "foo" or "zap" activates the external link, clicking on "bar" activates the internal link. But I see no reason to use such a structure, and the HTML developers probably did not see it either, so they decided to ban it and thereby simplify things.
(If you really want to simulate nested links, you can use a regular link as an external link and a span element with a suitable event handler as an internal link). Alternatively, you can duplicate links: <a href=foo>foo</a> <a href=bar>bar</a> <a href=foo>zap</a> .)
Jukka K. Korpela Oct 24 '12 at 17:55 2012-10-24 17:55
source share