[jQuery] Odd behaviour with append()

[jQuery] Odd behaviour with append()

What happens with the content variable?
Where does the projects variable come from?
Don't you end up with multiple infobar ids?
.append() only clones the element if there is a single node matched,
otherwise the nodes will move if they are already in the DOM tree since it
uses appendChild().
-----Original Message-----
From: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com] On
Behalf Of Phillip B Oldham
Sent: Tuesday, June 27, 2006 11:31 AM
To: Mailing List: jQuery
Subject: [jQuery] Odd behaviour with append()
Hi guys
I've got some code similar to the following HTML:
<div id="container">
<div id="content"><a href="#">Title</a> <blockquote>blah</blockquote></div>
</div>
And some javascript as such:
$('#content a').click(function(){
var content = $('../../.projects', this).get(0);
alert(this.innerHTML); // just to see whats in "this" object
$('#container').append('<div id="infobar"></div>');
$('#container #infobar').append(projects).slideDown('slow');
});
$('#container #infobar').click(function(){ this.slideUp(); });
What I've noticed is that on the first click, things run as expected, and
the infobar slides down containing the blockquote. Clicking the infobar
closes it, again as expected. Whats unexpected is that clicking again slides
down the infobar, but the content is missing. The alert shows that on the
second click the innerHTML of the content div only contains the a element,
and nothing more.
I was expecting to make a copy of the blockquote and append it to the
infobar, but it seems to have *moved* it instead.
Can anyone offer an explanation and fix?
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/