Delete <option> from <select> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Delete <option> from <select>

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script>
removeIt = function()//from  w  w  w  .j a v  a2  s.com
{
    var theSelect = document.getElementById("theSelect");
    var theOption = document.getElementById("theOption");
    theSelect.removeChild(theOption);
};

      </script> 
   </head> 
   <body> 
      <select id="theSelect"> 
         <option>1</option> 
         <option id="theOption">2</option> 
         <option>3</option> 
      </select> 
      <input type="button" onclick="removeIt()" value="remove it!">  
   </body>
</html>

Related Tutorials