You are here: Reference > JavaScript > client-side > HTML DOM > methods > remove (select)

remove method (select)

Browser support:
Removes the specified option element or the option element at the specified position from the options collection of the current select element.
This method is identical to the remove method of the options collection, but the remove method is not supported by Firefox.
If you want to insert an option element into the options collection, see the page for the add method.

Syntax:

object.remove (index);
You can find the related objects in the Supported by objects section below.

Parameters:

index
Required. A zero-based integer that specifies the position of the element or a reference to the option element to remove.
Note: Only integer values are supported for this parameter in Opera. For a cross-browser solution, if you want to remove an option element by reference, use the removeChild method.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the remove method:
<head>
    <script type="text/javascript">
        function RemoveFirstOption () {
            var selectTag = document.getElementById ("mySelect");
            selectTag.remove (0);
        }
    </script>
</head>
<body>
    <select id="mySelect" size="5">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
    </select>
    <button onclick="RemoveFirstOption ()">Remove the first option</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content