I have multiple select elements that I need to get the same options using Javascript. They all have the same class. This code works with an id but not with class.
I tried changing getElementById to getElementsByClassName, but that doesn't seem to work. I am pretty new to Javascript and don't completely understand the difference between these two commands.
The code:
<select class="phoneNumber"></select>
<script>
phoneNumber = document.getElementById("phoneNumber");
var option = document.createElement('option'); option.text = '1234567897'; phoneNumber.appendChild(option);
var option = document.createElement('option'); option.text = '1233213211'; phoneNumber.appendChild(option);
</script>