How can I get the selected text (not the selected value) from a drop-down list in jQuery?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
Use:
$("#DropDownID").val()
will give the selected index value.The answers posted here, for example,
didn't work for me, but this did:
It is possibly an older version of jQuery.
Instead of
#selectID
you can use any jQuery selector, like.selectClass
using class.As mentioned in the documentation here.
The :selected selector works for <option> elements. It does not work for checkboxes or radio inputs; use
:checked
for them..text() As per the documentation here.
Get the combined text contents of each element in the set of matched elements, including their descendants.
So you can take text from any HTML element using the
.text()
method.Refer the documentation for a deeper explanation.