I am looping over select drop down options and want to remove an option if its value meets certain specified condition. I used selectObject.removechild(option)/option.remove(), but in doing so only one option that meets the condition first removes but not others because at each deletion operation the size of the list reduces and hence all options not get traversed. I want pure JavaScript solution (no JQuery). I searched much and only found JQuery solutions. Is there any other way?
var selectObject = document.getElementById("sel");
var opts = selectObject.options;
for(var i = 0; opts.length; i++){
if(opts[i].value == val){
opts[i].remove();
//i also tried with: selectObject.removeChild(opts[i])
}
}