A user on a forum recently asked a question on how you clear the items in a drop down list using jQuery.
<asp:DropDownList ID="ddlPeople" runat="server">
The answer to the problem is in the jQuery Selector. The person was using the following jQuery to try and clear the items, but it wasn’t working:
The items weren’t being removed because the jQuery Selector is wrong. What you need to do is tell the Selector to remove all the children (<option> tags). Like this:
$("select[id$=ddlPeople] > option").remove();
“> option” matches all child elements. Because each item in the drop down list is rendered as an <option> tag, you need to clear the child <option> tags in order to clear the items in a drop down list.