tags:

views:

30

answers:

3

Hello, I'm using prepend() and the result seems to be buggy.

$('#element').prepend('<div><a href="http://google.com"&gt;&lt;a href="http://test.com"&gt;Test.com&lt;/a&gt; - A site</a></div>');

And the html result (also viewed with Firebug) is buggy:

<div>
    <a href="http://google.com"&gt;&lt;/a&gt;
    <a href="http://test.com"&gt;Test.com&lt;/a&gt; - A site
</div>

(The links are just example links)

+3  A: 

You can't have an anchor inside an anchor...so it's not "buggy", it's behaving unexpectedly with invalid HTML, but when HTML is invalid that's...well, expected.

Think about it this way, if you clicked on the inside anchor, where should your browser go? You clicked on http://test.com and http://google.com.

Nick Craver
+1  A: 

As I know, nested links (the a elements) are not allowed in html. So browser closes first before the second. It has no connection to jQUery.

pepiino