Clear and append item to select

Description

The following code shows how to clear and append item to select.

Example


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>//<![CDATA[ 
window.onload=function(){<!-- w  w w.j a  va 2  s.  co  m-->
var count = 3;
$(document).delegate('a', 'click', function () {
    $('select').empty().append('<option value="' + count + '">Option ' + (count++) + '</option><option value="' + count + '">Option ' + (count++) + '</option>').selectmenu('refresh');
    return false;
});
}//]]>  
</script>
</head>
<body>
  <link rel="stylesheet"
    href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
  <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
  <script
    src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
  <div data-role="page">
    <div data-role="content">
      <select id="searchReasonList" name="searchReasonList"
        data-placeholder="true">
        <option value="">Select Reason</option>
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
      </select> <a data-role="button" href="#">Reload Select</a>
    </div>
  </div>
</body>

Click to view the demo





















Home »
  jQuery Mobile »
    Example »




Button
Button Event
Button Icon
Button Text
Checkbox
Collapsible
Date
Dialog
Event
Footer
Form
Header
Icon
Input
Layout
Listview
Listview Divider
Listview Item
Loader
mobile_settings
Navbar
Page
Page Event
Popup
Radio
Select
Slider
Switch
Textarea
Theme