Remove the selected option from the drop-down list:
<!DOCTYPE html> <html> <body> <form> Select a fruit: <br> <select id="mySelect" size="4"> <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option> </select> </form>/* ww w. j a va 2s .co m*/ <br> <button onclick="myFunction()">Remove selected fruit</button> <script> function myFunction() { var x = document.getElementById("mySelect"); x.remove(x.selectedIndex); } </script> </body> </html>
The remove()
method is used to remove an option from a drop-down list.
Parameter Values
Parameter | Description |
---|---|
index | Required. Specifies the index of the option to remove. Index starts at 0 |