<select> <option value="test">label </option> </select> The value can be retrieved by $select.val().
What about the label?
Is there a solution that will work in IE6?
<select> <option value="test">label </option> </select> The value can be retrieved by $select.val().
What about the label?
Is there a solution that will work in IE6?
Try this:
$('select option:selected').text(); Try this:
$('select option:selected').prop('label'); This will pull out the displayed text for both styles of <option> elements:
<option label="foo"><option> -> "foo"<option>bar<option> -> "bar"If it has both a label attribute and text inside the element, it'll use the label attribute, which is the same behavior as the browser.
For posterity, this was tested under jQuery 3.1.1
In modern browsers you do not need JQuery for this. Instead use
document.querySelectorAll('option:checked') Or specify any DOM element instead of document
element.textContentCreated working Plunker for this. https://plnkr.co/edit/vR9aGoCwoOUL9tevIEen $('#console').append("<br/>"+$('#test_s :selected').text())
You're looking for $select.html()