jQuery .val() supports select elements

Did you know that you can get selected options for select elements with simple jQuery .val() method?

Somehow I was under impression it only scrapes “value” attribute, which is not the case for select element and used to look for selected option element. However, recently I found that .val() it works fine for both drop-down and multi-select elements. In the latter case it even returns an array of selected values.

Still you need something like $(‘#mySelect’).find(‘option:selected’).text() if you’re looking for user-friendly label of selected element(s) rather than it’s value attribute. And still .val() doesn’t work for radio-buttons as they are multiple elements.

Leave a Comment