Appending new option to dropdown list dynamically as selected - Javascript jQuery

Javascript examples for jQuery:Selector

Description

Appending new option to dropdown list dynamically as selected

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from   w w  w .j  ava  2s.  c o m*/
$('#department').append(new Option(4, 4, false, true));
    });

      </script> 
 </head> 
 <body> 
  <select name="" id="department"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select>  
 </body>
</html>

Related Tutorials