Currently, I'm attempting to assign a unique className to option elements within a select element by utilizing a conditional if statement. The goal is to apply one class name to the first half of the array and a different class name to the second half. In order to set the disabled value for every option element to 'true' upon page load, this conditional statement is enclosed within a for loop.
Despite the loop executing and the conditionals being evaluated, an issue arises where all option elements receive the same class name. After researching online without success, it's time to seek assistance through my own query.
Below is a snippet of the code in question. (Please note that the array's length is 6)
for (let i = 0; i < array.length; i++) {
array[i].disabled = true;
if (array[i] <= 2) {
array[i].className = 'classOne';
} else {
array[i].className = 'classTwo';
}
}
Consequently, each option element ends up having the className of "classTwo". It has proven to be quite challenging to troubleshoot this dilemma.
I would greatly appreciate any guidance or solution provided!