I have an HTML Select box with about 1800+ options. In my javascript I have the following line to empty the select box so I can repopulate it.
box.options.length = 0;
In Firefox this runs fairly quickly, but IE takes a couple of seconds. Is there a faster way to do this in IE?
You could use
box.innerHTML="". In my test, it is 68% faster:http://jsperf.com/emptying-a-select-box/4.
Update: in 2015
box.innerHTML = ""is by multiple orders of magnitude the slowest option. 🙂 Usebox.options.length = 0instead.