Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to remove all items from dropdown list or listbox?

Tags:

javascript

I have a dropdown list with more than one thousand items. Once I click on clear button it should clear all items. For removing I tried looping.

What would be the fastest way to remove all items from a dropdown list or listbox?

like image 552
Kuldeep Shige Avatar asked Dec 01 '25 15:12

Kuldeep Shige


2 Answers

Set innerHTML of select box as empty string.

var selectBox = document.getElementById("selectboxID");
selectBox.innerHTML = "";
like image 78
Anoop Avatar answered Dec 03 '25 05:12

Anoop


An option if you're using jQuery:

$("#selectboxID").empty();
like image 35
Tim Avatar answered Dec 03 '25 04:12

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!