开发者

Append or prepend opening/closing tags with jQuery

开发者 https://www.devze.com 2022-12-25 15:27 出处:网络
I\'m trying to wrap replies in a comment stream in alike this: $(\'li.comment\').next(\'li.replycomment\').append(\'<ul class=\"thre开发者_高级运维ad\">\');

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消