Reputation: 104741
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?
Upvotes: 1
Views: 190
Reputation: 193261
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
).
For example, if you have this HTML structure:
<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
$('.div').remove('.a');
In your case you need to use find
method and then remove found inputs.
Upvotes: 3