In my current code, I like
$("#foo").remove(); $("#bar").remove();
Is there a way to remove multiple elements using remove() once?
remove()
It is not limited to .remove() , but simply separates the selector with a comma:
.remove()
$("#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.
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.
Separating multiple elements requires comma-separated multiple selectors . Try the following:
$("#foo,#bar").remove();
To select multiple items in jQuery syntax
$('#foo, #bar').remove();
Remove some empty div tags.
$(".className1.className2").each(function() { var current_element = $(this); if(current_element.text().trim()==""){ current_element.remove(); } });