Home JQuery How to remove all options within a Html select box using JQuery?
 
 
 

How to remove all options within a Html select box using JQuery?

PDF Print E-mail

Question: How to remove all options within a Html select box using JQuery?

 

Answer:

You have a html select box "combo box" 

 
<select id="selectBox">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
 

 In order to remove all items using JQuery use the JQuery empty function

 
$('#selectBox').empty();

Replace selectBox with the relevant id for the select box

 

If you wish to empty the select box and add a single option to the select box, use JQuery's append function together with the empty function

$('#selectBox').empty().append('<option>New Option</option>');
This will add the New Option to the select box.

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!