gpt4 book ai didi

jquery - 使用 jQuery remove() 从元素中删除某些子元素

转载 作者:行者123 更新时间:2023-12-01 07:18:45 33 4
gpt4 key购买 nike

根据文档,http://api.jquery.com/remove/ ,看起来

$('#id').remove('.class');

应该具有与

相同的效果
$('#id').children('.class').remove();

但是,只有后者按预期工作。

我做错了什么或者误解了文档吗?

最佳答案

您误解了文档。

传递给 .remove() 的选择器会过滤集合本身,而不是任何子元素。
换句话说,你可以写

$('#id').children().remove('.class');

或者

$('#id > *').remove('.class');

关于jquery - 使用 jQuery remove() 从元素中删除某些子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16105328/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com