Skip to content Skip to sidebar Skip to footer

How To Remove Multiple Options In A Select Tag Using Jquery

I am trying to delete two options from a select tag using jQuery using the following code $('#selectionid option[value='option1']').remove(); $('#selectionid option[value='option

Solution 1:

You can try

$("#selectionid option[value='option1'], #selectionid option[value='option2']").remove();

Solution 2:

In a single line you can remove like

$('#selectionid option').filter('[value="option1"],[value="option2"]').remove();

Demo

Solution 3:

You could simply use this line to delete both:

$("#selectionid option[value='option1'], #selectionid option[value='option2']").remove();

Or you could use this bind to display everything expect for the ones you want 'deleted'.

var list = ["option1", "option2"];
$('select option').filter(function () {
   return $.inArray(this.value, list) !== -1
}).remove();

Example (JSFiddle)

Solution 4:

Have you tried wildcard selectors? I believe it'd be something like:

$("#selectionid option[value*='option']").remove();

Post a Comment for "How To Remove Multiple Options In A Select Tag Using Jquery"