I have a page where I have many select
s that show tons of options (think of something like 75 select
s with 200 hundred options each). I realize that this is ugly/bad idea/etc. To make things a bit more snappy, I only include one option
by default in each select and then on the click
event, I add the rest. This works fine, but there is a split-second when the select
shows its drop-down that only has one option
and then shows the rest a split-second later.
Is there a way to "pause" the drop-down from showing itself until after I have added the other 'option's?
Here is the code if that helps:
$(document).on('click', 'select', function(){
var thisJQ = $(this);
if (thisJQ.children().length > 1) {
return;
}
var values = otherOptions ; // defined elsewhere
var optSelected = thisJQ.children('option:selected');
var opts = [];
values.forEach(function(obj, index){
if (parseInt(optSelected.val(), 10) === obj["id"]) {
return;
}
var opt = document.createElement('option');
opt.appendChild(document.createTextNode(obj["desc"]));
opt.setAttribute('value', obj["id"]);
opts.push(opt);
})
thisJQ.append(opts);
});