I ma trying to get selected values from select element with multiple attribute. jQuery would return an array, but javascript only retuerns single value if multiple are selected.
var fruits = document.getElementById('fruits')
fruits.addEventListener('change', function() {
var selected = fruits.value
console.log(selected)
})
<select multiple="true" id="fruits">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="mango">Mango</option>
<option value="grape">Grape</option>
<option value="watermelon">watermelon</option>
</select>
2
Answers
using the
selectedOptions
you can access the currently selected elementsThe cleanest way would probably be to use the selectedOptions property