I found out jQuery does not always create the correct DOM from an HTML string. Here is a little example code:
var x = "<div><p><ul><li>1</li></ul></p></div>";
console.log('x = ' + x);
console.log('jQuery(x) = ' + jQuery(x).html());
var y = "<div><div><ul><li>1</li></ul></div></div>";
console.log('y = ' + y);
console.log('jQuery(y) = ' + jQuery(y).html());
Here is the output I get running this with jQuery 1.7.1:
x = <div><p><ul><li>1</li></ul></p></div>
jQuery(x) = <p></p><ul><li>1</li></ul><p></p>
y = <div><div><ul><li>1</li></ul></div></div>
jQuery(y) = <div><ul><li>1</li></ul></div>
As you can see, the second example creates the correct DOM, the first example does not. The only difference is a <p>
tag instead of a <div>
. Is this a bug or feature of jQuery?