Html嵌套元素移除类

Html nested element remove class

本文关键字:元素 嵌套 Html      更新时间:2023-09-26

HTML

<li id="tree0_2_2" data-rowkey="0_2_2">
    <span>
       <span></span>
       <span></span>
       <span class="ui-state-highlight">Something</span>
    </span>
</li>

jQuery

var removedNode = $('#tree0_2_2');
$(removedNode.find(".ui-state-highlight")).removeClass('.ui-state-highlight');

我试过了,但没用。

如何删除类'i-state-higlight'

您可能错过了结束报价,并从removeClass 中删除了.

实时演示

var removedNode = $('#tree0_2_2');
removedNode.find(".ui-state-highlight").removeClass('ui-state-highlight');

removedNode是jQuery对象,不需要再次将其传递给$()。您可以将其简化为单个语句。

实时演示

$('#tree0_2_2 .ui-state-highlight').removeClass('ui-state-highlight');

.中不需要在removeClass:中的类名之前

$('#tree0_2_2').find('.ui-state-highlight').removeClass('ui-state-highlight');

注意:您实际上不需要多次将jQuery对象封装在另一个jQuery对象中,只需执行一次即可,如上面的解决方案所示。

试试这个。您的代码包含许多语法错误

$('#tree0_2_2').find("span.ui-state-highlight").removeClass('ui-state-highlight');

你的代码就像这个

var removedNode = $('#tree0_2_2');
removedNode.find(".ui-state-highlight").removeClass('ui-state-highlight');

Try,

$("#tree0_2_2 .ui-state-highlight").removeClass('ui-state-highlight');

$(".ui-state-highlight", "#tree0_2_2").removeClass('ui-state-highlight');

HTML:

<li id="tree0_2_2" data-rowkey="0_2_2">
    <span>
       <span></span>
       <span></span>
       <span class="ui-state-highlight">Something</span>
    </span>
</li>

JQuery:

var removedNode = $('#tree0_2_2');
removedNode.find(".ui-state-highlight").removeClass('ui-state-highlight');

生成变量后,您不需要编写$(removedNode.find())