THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Select remove() Method

Select Object Reference Select Object

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

Internet Explorer Firefox Opera Google Chrome Safari

The remove() method is supported in all major browsers.


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 Reference Select Object