Select remove() Method
Example
Remove the selected option from the drop-down list:
var x = document.getElementById("mySelect");
x.remove(x.selectedIndex);
Try it Yourself »
Definition and Usage
The remove() method is used to remove an option from a drop-down list.
Tip: To add an option to a drop-down list, use the add() method.
Browser Support
Method | |||||
---|---|---|---|---|---|
remove() | Yes | Yes | Yes | Yes | Yes |
Syntax
selectObject.remove(index)
Parameter Values
Parameter | Description |
---|---|
index | Required. Specifies the index of the option to remove. Index starts at 0 |
Technical Details
Return Value: | No return value |
---|
More Examples
Example
Remove the option with index "2" from a drop-down list:
var x = document.getElementById("mySelect");
x.remove(2);
Try it Yourself »
Example
Remove the last option from a drop-down list:
var x = document.getElementById("mySelect");
if (x.length > 0) {
x.remove(x.length-1);
}
Try it Yourself »
Select Object