How to remove options from a dropdown list with JavaScript?

HTMLJavascriptProgramming Scripts

To remove options from a dropdown list, use the remove() method in JavaScript. You can try to run the following code to learn how to remove options from the drop-down −

Example

Live Demo
<!DOCTYPE html>
<html>
   <body>
      <form id = "myForm">
         <select id = "selectNow">
            <option>One</option>
            <option>Two</option>
            <option>Three</option>
         </select>
         <input type = "button" onclick = "remove()" value = "Click to Remove">
      </form>
      <p>Select and click the button to remove the selected option.</p>
      
      <script>
         function remove() {
            var x = document.getElementById("selectNow");
            x.remove(x.selectedIndex);
         }
      </script>
      
   </body>
</html>
raja
Published on 26-Feb-2018 13:29:07
Advertisements