views:

27

answers:

1

In the Jquery example below, I would like to expand $(this) before it is cloned, so it includes everything contained in the parent class "comment". How do I do this? I've tried using ReplaceWith($(this).parent('.comment').clone()... and it does not work!

$(document).ready(

function(){ 

$('.forumthreadtitle').siblings().hide(); 
$('.forumthreadtitle').click( function() {
$('#first-post').replaceWith($(this).clone().attr('id','first-post'));

});
+2  A: 

To get the closest class="comment" parent and clone it, do this:

$(this).closest(".comment").clone();

.parent(selector) only finds if it's the immediate parent. The equivalent for this (since comment isn't the element itself) would be: .parents(".comment:first").

Nick Craver
I would like clone everything below the comment class - all of comment's children - not just comment. Do I have to change this code at all to do so? In my testing of this code the parent's children are not being reproduced in the clone...
HipHop-opatamus