[英]jQuery .remove(Selector) doesn't work
Look at this snippet: 看看这个片段:
var div = $('#createDrugForm');
div.remove('input[type=hidden]');
//the hidden field is still there
div.find('input[type=hidden]').remove();
//the hidden was removed
Why does the first method of removal not work? 为什么第一种移除方法不起作用?
When you provide a selector to $.fn.remove
method, this selector is used to filter already selected collection (see $.fn.filter
), but not to find new child elements (see $.fn.find
). 当您为
$.fn.remove
方法提供选择器时,此选择器用于过滤已选择的集合(请参阅$.fn.filter
),但不能查找新的子元素(请参阅$.fn.find
)。
For example, if you have this HTML structure: 例如,如果您有此HTML结构:
<div class="div a">a</div>
<div class="div b">b</div>
<div class="div c">c</div>
you can remove .a
div with this code 你可以用这个代码删除
.a
div
$('.div').remove('.a');
In your case you need to use find
method and then remove found inputs. 在您的情况下,您需要使用
find
方法,然后删除找到的输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.