How can I get the selected text (not the selected value) from a drop-down list in jQuery?
Use this
const select = document.getElementById("yourSelectId");
const selectedIndex = select.selectedIndex;
const selectedValue = select.value;
const selectedText = select.options[selectedIndex].text;
Then you get your selected value and text inside selectedValue
and selectedText
.
$("option:selected", $("#TipoRecorde")).text()
This code worked for me.
$("#yourdropdownid").children("option").filter(":selected").text();
Various ways
1. $("#myselect option:selected").text();
2. $("#myselect :selected").text();
3. $("#myselect").children(":selected").text();
4. $("#myselect").find(":selected").text();
var someName = "Test";
$("#<%= ddltest.ClientID %>").each(function () {
$('option', this).each(function () {
if ($(this).text().toLowerCase() == someName) {
$(this).attr('selected', 'selected')
};
});
});
That will help you to get right direction. Above code is fully tested if you need further help let me know.
Simply try the following code.
var text= $('#yourslectbox').find(":selected").text();
it returns the text of the selected option.