How do I remove items from, or add items to, a select box? I'm running jQuery, should that make the task easier. Below is an example select box.
<select name="selectBox" id="selectBox">
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
<option value="option4">option4</option>
</select>
I just want to suggest another way to add an
option
. Instead of setting thevalue
andtext
as a string one can also do:This is a less error-prone solution when adding options' values and texts dynamically.
If somebody need delete ALL options inside a select, i did a litle function.
I hope you find it useful
Only have to run
I found two pages that seem helpful, it's written for ASP.Net, but the same stuff should apply: