Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-populate drop down list options, how to clear options list and then re-populate?

Tags:

jquery

ajax

Re-populate drop down list options, how to clear options list and then re-populate?

When a event fires, I need to wipe out the current contents of the drop down list #users, and then re-populate it via ajax.

My ajax call is returning the HTML for the options like:

<option name=blah1>text1</option>
<option name=blah2>text2</option>
<option name=blah3>text3</option>
like image 764
Blankman Avatar asked Nov 09 '10 16:11

Blankman


People also ask

How do I remove a selected value from a Dropdownlist?

Use the :selected pseudo-selector to select the selected option from the dropdown and remove() to remove it from DOM.

How do I remove all options from a select?

We select all the options in the select box using the find() method with a parameter of “option“. Then, we remove all the selected options using the remove() method.

How do I remove a drop down list in HTML?

Select remove() Method The remove() method is used to remove an option from a drop-down list.


1 Answers

you can use the below

$('#mySelect').empty()

and then rebind the new data.

like image 182
kobe Avatar answered Oct 05 '22 11:10

kobe