jQuery jquery从特定id中删除特定元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6629414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:09:20  来源:igfitidea点击:

jquery remove specific element from a specific id

jquery

提问by Yannick

I have 2 div like this:

我有 2 个这样的 div:

<div id="container1"><input class="1"><input class="2"></div>

<div id="container2"><input class="1"><input class="1"><input class="2"></div>

Now how do I remove all class="1" but only from the container2.

现在如何删除所有 class="1" 但仅从 container2 中删除。

回答by Jamie Treworgy

This should do it.

这应该这样做。

$('#container2 .1').remove();

$('#container2 .1').remove();

This seeks all descendants from the element with id "container2" which belongs to the class named "1" and then remove them from the DOM.

这会从 id 为“container2”的元素中寻找所有后代,该元素属于名为“1”的类,然后将它们从 DOM 中删除。