X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook