Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. I don't recommend doing DOM manipulations inside a loop -- that can get expensive in large datasets. Instead, I would do something like this: var e Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. To review, open the file in an editor that reveals hidden Unicode characters. The read-only HTMLSelectElement property selectedOptions contains a list of the