如何在div标签中添加一个类,在同一个句子中使用jquery将另一个类添加到ul标签?

时间:2017-07-11 01:34:42

标签: jquery html

我只添加了一个......

$(this).replaceWith($('<div> <ul>' + this.innerHTML + '</ul></div>').addClass('card_tr'));

这是我为文本编辑器拍摄的图像,我是新的。

enter image description here

3 个答案:

答案 0 :(得分:0)

如果您使用children,您将获得不同的选择器结果集,因此您可以将方法链接在一起以获得所需的效果。

$("DIV").addClass("class-for-div")   //Will apply only to the DIV
        .children("UL")
        .addClass("class-for-ul");   //Will apply only to the UL children and not the DIV itself

答案 1 :(得分:0)

假设您的代码行正常工作......但唯一缺少的是要添加到ul的类......

为什么不在指定replaceWith()的内容时添加它?

$(this).replaceWith($('<div> <ul class="HELLO">' + this.innerHTML + '</ul></div>').addClass('card_tr'));

答案 2 :(得分:0)

您可以尝试这种方法。

{{1}}