Select remove() Method
Definition and Usage
remove()
This method is used to remove options from the dropdown list.
Tip:To add an option to the dropdown list, use add() method.
Instance
Example 1
Remove the selected option from the dropdown list:
var x = document.getElementById("mySelect"); x.remove(x.selectedIndex);
Example 2
Remove the option at index "2" from the dropdown list:
var x = document.getElementById("mySelect"); x.remove(2);
Example 3
Remove the last option from the dropdown list:
var x = document.getElementById("mySelect"); if (x.length > 0) { x.remove(x.length-1); }
Syntax
selectObject.remove(index)
Parameter Value
Parameter | Description |
---|---|
index | Required. Specifies the index (subscript) of the option to be removed. The index starts from 0. |
Technical Details
Return Value:
No Return Value.
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |