- how can i select all the ‘select element’ from HTML, and get the value from the option selected.
- how can i retrieve value that’s selected from the option,
i want to iterate through the select elements and get the selected value,
like a dropdown list from an e-commence website, where a user can select the quantity of the product they want.
i tried using querySelectorAll to get all the ‘select element’
document.querySelectorAll('.js-quantity-selector')
.forEach((selectedOption)=>{
const optionSelected = selectedOption.options[selectedOption.selectedIndex];
});
New contributor
Okon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.