In my current code I have like
$("#foo").remove();
$("#bar").remove();
Are there any way to remove multiple elements by using remove()
once?
It's not limited to .remove()
, but just separate the selectors by a comma:
$("#foo, #bar").remove();
Multiple Selector (“selector1, selector2, selectorN”) | jQuery API Documentation
Description: Selects the combined results of all the specified selectors.
jQuery( "selector1, selector2, selectorN" )
selector1: Any valid selector.
selector2: Another valid selector.
selectorN: As many more valid selectors as you like.
You need comma separated multiple selector to target multiple elements.Try this:
$("#foo,#bar").remove();
To select multiple elements in jQuery, the syntax is
$('#foo, #bar').remove();
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