Append or prepend opening/closing tags with jQuery
I'm trying to wrap replies in a comment stream in a like this:
$('li.comment').next('li.replycomment').append('<ul class="thre开发者_高级运维ad">');
$('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?
I believe you want:
$('li.comment').next('li.replycomment').wrap('<ul class="thread"></ul>');
Because it's invalid HTML. Try using wrap() instead.
精彩评论