How we can remove the all div by same name of class.
<input class="form-control" type="text" name="option[]"><input class="form-control" type="text" name="option[]"><input class="form-control" type="text" name="option[]">
Try with querySelectorAll()
And NodeList#forEach
use to iterate the element
document.querySelectorAll('.classname').forEach(function(a){
a.remove()
})
Example snippet
document.querySelectorAll('.form-control').forEach(function(a) {
a.remove()
})
<input class="form-control" type="text" name="option[]">
<input class="form-control" type="text" name="option[]">
<input class="form" type="text" name="option[]" value="not same class">
<input class="form-control" type="text" name="option[]">
My approach might be this
var elements = document.querySelectorAll('.test');
for (var element of elements) {
element.remove();
// or
// element.parentNode.removeChild(element);
}
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With