Why do you think getElementById
, specifically, isn’t working? The problem is more along the lines of not being able to apply display: none
to <option>
elements. The easiest fix would probably be to set disabled
for it:
document.getElementById("B2").disabled = choose_option === 4;
If you want it to really be gone, that would be done by removing it:
var nextMenu = document.getElementById("nextMenu");
var b2 = document.getElementById("B2");
function testOptions() {
var choose_option = document.getElementById("testMenu").selectedIndex + 2;
if (choose_option === 4) {
if (b2.parentNode) {
b2.parentNode.removeChild(b2);
}
} else if (!b2.parentNode) {
nextMenu.appendChild(b2);
}
}