Inconsistent jQuery Set

Calling clone() and then appendTo() can result in different jQuery set in different browsers. IE6+ (haven't tested IE9) doesn't introduce a new jQuery set after calling appendTo().

by gravof

HTML

The expected result is:<br>
foobar<br>
<br>
The actual result is:<br>
<div id="result"></div>

JavaScript

var $foo = $('<p/>')
    .clone()
        .addClass('foo')
        .appendTo('<div/>')
        .end();

$('#result').text($foo.attr('class'));

var $bar = $('<p/>')
    .clone()
        .addClass('bar')
        .appendTo('<div/><div/>')
        .end();

$('#result').text($('#result').text() + $bar.attr('class'));