I created a dropdown menu with the Select HTML code.
How can I disable all element at once, without looping through them?
I tried the following, but it leads to the dropdown being disabled, rather than its individual elements:
var select = document.getElementById(“myDropdown”);
select.setAttribute(“disabled”, " ");
Kind regards and many thanks
To disable all options within a
<select> dropdown without disabling the dropdown itself, you indeed need to apply the disabled attribute to each
You can do it in a relatively concise one-liner, though:
document.querySelectorAll('#myDropdown option').forEach(option => option.disabled = true);
Yes but for what should this be good? You waste the users time to click on something he cannot use….
This is great help, many thanks!
it actually is part of a bigger problem. I first disable all elements, and then enable some elements for which specifc conditions hold