views:

219

answers:

2

I'm trying to wrap replies in a comment stream in a like this:

$('li.comment').next('li.replycomment').append('<ul class="thread">');
$('li.replycomment').next('li.comment').prepend('</ul>');

It doesn't work unfortunately. If I do the following it works no problem:

 $('li.comment').next('li.replycomment').append('<ul class="thread"><li>awesome</li></ul>');
    $('li.replycomment').next('li.comment').prepend('<ul><li>radical</li></ul>');

Is there a reason jQuery won't let me insert an unclosed tag?

+1  A: 

Because it's invalid HTML. Try using wrap() instead.

Matt Ball
+3  A: 

I believe you want:

$('li.comment').next('li.replycomment').wrap('<ul class="thread"></ul>');
James Curran