How can I get the selected text (not the selected value) from a drop-down list in jQuery?
-
13Just my two cents: An "ASP" drop-down is no special; it's just good old HTML. :-) – ankush981 Jun 04 '15 at 06:20
-
One can refer this article: http://javascriptstutorial.com/blog/selecting-dropdown-element-using-javascript-or-jquery/ – Dilip Kumar Yadav Oct 18 '16 at 12:02
-
for vanilla javascript way, see http://stackoverflow.com/a/5947/32453 – rogerdpack Jan 18 '17 at 19:27
-
Just $(this).prop('selected', true); replaced .att to .prop it worked for all browsers – Shahid Hussain Abbasi Jan 12 '19 at 11:13
34 Answers
$("#yourdropdownid option:selected").text();
![](../../users/profiles/47738.webp)
- 174,563
- 47
- 223
- 254
-
212I think this should be `$("#yourdropdownid").children("option").filter(":selected").text()` since is() returns a boolean of whether the object matches the selector or not. – MHollis May 18 '12 at 14:04
-
44I second the comment about is() returning a boolen; alternatively, use the following small alteration: $('#yourdropdownid').children("option:selected").text(); – scubbo Jun 12 '12 at 14:56
-
25@DT3 tested `is("selected").text()` returns a `TypeError: Object false has no method 'text'` – ianace Oct 19 '12 at 07:20
-
2@DT3, he's not wrong about the speeds. [Here are some quick stats](http://grabilla.com/02c04-34774c6b-bb36-4324-878b-25f4ba6ca94d.html) run on a realistically sized dropdown (8 or so). – Adam Tomat Dec 04 '12 at 15:20
-
98`$('select').children(':selected')` is the fastest way: http://jsperf.com/get-selected-option-text – Simon Apr 24 '13 at 13:51
-
1@Sandeep .val() will return the value of the option element, whereas the OP wants the text contained in the option element: e.g. for the following 'foo' rather than 'bar' is wanted – jinglesthula Mar 18 '14 at 18:04
-
3
-
2I'll add this to the mix, especially if you already have a handle to the dropdown element: $select.find("option:selected").text(); – Draghon Jun 17 '16 at 16:10
-
Hi how do you do this inside a Table row/cell, how do you know which of the Dropdwon from the table – Transformer Mar 12 '17 at 07:40
-
Just to add up to the post, is you need it by the field name would be like this: $("[name='input_name'] option:selected").text(); – viniciusalvess Jul 02 '17 at 15:44
-
@MHollis your way is good but too long. this method is useful when we have some dynamic elements on document. – Hemant Sankhla Jul 13 '17 at 11:18
-
3
Try this:
$("#myselect :selected").text();
For an ASP.NET dropdown you can use the following selector:
$("[id*='MyDropDownId'] :selected")
![](../../users/profiles/24054.webp)
- 96,871
- 26
- 155
- 191
-
The ASP.NET version here is the only Jquery that works with asp.net for me, I hence assent to that one. This one: (**'$("#yourdropdownid option:selected").text();'** did not work in an asp.net page using a master page. – netfed Sep 09 '13 at 16:40
-
5it doesn't work because asp.net master pages throws random characters in front of the selector. It's technically looking for something like `("#ct0001yourdropdownid) ` – CSharper Apr 03 '14 at 17:06
-
http://javascriptstutorial.com/blog/selecting-dropdown-element-using-javascript-or-jquery/ – Dilip Kumar Yadav Oct 18 '16 at 12:03
-
1@CSharper - I think saying ASP.NET *throws random characters* is rather misleading. They're not random at all, they're structural and follow strict rules (based on things like whether you put an `ID` on your control, and if not then based on the index of where they occur in the current level of the tree, etc) – freefaller Mar 09 '17 at 14:03
-
Hi how do you do this inside a Table row/cell, how do you know which of the Dropdown from the table, especially in ASP MVC 5 – Transformer Mar 12 '17 at 07:41
-
You can also do $("#''"), but the selectors are cleaner. If you had a lot of controls and you were in a looping scenario then it might benefit you to use the id, but I've never had a performance issue using the selector method. – Charles Byrne Nov 28 '17 at 13:40
The answers posted here, for example,
$('#yourdropdownid option:selected').text();
didn't work for me, but this did:
$('#yourdropdownid').find('option:selected').text();
It is possibly an older version of jQuery.
![](../../users/profiles/63550.webp)
- 28,342
- 21
- 95
- 123
![](../../users/profiles/1199713.webp)
- 2,453
- 1
- 15
- 14
-
7Don't be hating on this answer. Using the "find" keyword did the trick for me. I was coming from a completely different context. – Gaff Aug 06 '12 at 13:50
-
5you don't need the option part at all as its implied with selected.. simply using $('#yourdropdownid :selected').text(); will work fine – Dss Jan 17 '13 at 18:52
-
-
The popular answer works, but I needed it on an already obtained reference to the select, so this is the best answer for me – Graham Oct 22 '18 at 09:53
If you already have the dropdownlist available in a variable, this is what works for me:
$("option:selected", myVar).text()
The other answers on this question helped me, but ultimately the jQuery forum thread $(this + "option:selected").attr("rel") option selected is not working in IE helped the most.
Update: fixed the above link
![](../../users/profiles/2430556.webp)
- 1,119
- 2
- 25
- 44
![](../../users/profiles/74276.webp)
- 7,203
- 7
- 43
- 50
This works for me
$("#dropdownid").change(function() {
alert($(this).find("option:selected").text());
});
If the element created dynamically
$(document).on("change", "#dropdownid", function() {
alert($(this).find("option:selected").text());
});
![](../../users/profiles/4796478.webp)
- 3,070
- 1
- 16
- 17
$("option:selected", $("#TipoRecorde")).text()
![](../../users/profiles/656489.webp)
- 11,962
- 6
- 34
- 56
![](../../users/profiles/897238.webp)
- 661
- 5
- 2
-
this helped, cos I had to use $(this).. it was easy with this one. – The Godfather Sep 16 '20 at 09:44
![](../../users/profiles/63550.webp)
- 28,342
- 21
- 95
- 123
![](../../users/profiles/1611714.webp)
- 2,998
- 28
- 20
-
4This worked for me, because on the `change` event I can now use `$(this).find('option:selected').text()` to get text. – Timo002 Dec 08 '14 at 20:54
-
$("#DropDownID").val()
will give the selected index value.
![](../../users/profiles/309086.webp)
- 15,104
- 9
- 55
- 73
![](../../users/profiles/1045279.webp)
- 687
- 5
- 2
-
38Not exactly the answer to the question, but was useful for me. The question wants the selected text. – Peter Nov 28 '11 at 14:50
Various ways
1. $("#myselect option:selected").text();
2. $("#myselect :selected").text();
3. $("#myselect").children(":selected").text();
4. $("#myselect").find(":selected").text();
![](../../users/profiles/2459296.webp)
- 13,325
- 6
- 72
- 84
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
.
![](../../users/profiles/2188407.webp)
- 6,993
- 2
- 41
- 53
![](../../users/profiles/3345941.webp)
- 1,001
- 9
- 9
$("#dropdownID").change(function(){
alert($('option:selected', $(this)).text());
});
![](../../users/profiles/3058754.webp)
- 2,509
- 22
- 36
-
this is what, I was expecting with `$(this)` after my ajax call – Shantaram Tupe Nov 30 '16 at 06:40
-
You can also do $("option:selected", this).text() without wrapping this in a JQuery object. – Doug F Mar 05 '19 at 14:26
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.
For those who are using SharePoint lists and don't want to use the long generated id, this will work:
var e = $('select[title="IntenalFieldName"] option:selected').text();
![](../../users/profiles/63550.webp)
- 28,342
- 21
- 95
- 123
![](../../users/profiles/1212739.webp)
- 489
- 7
- 15
$("#selectID option:selected").text();
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.
![](../../users/profiles/63550.webp)
- 28,342
- 21
- 95
- 123
![](../../users/profiles/2218452.webp)
- 23,885
- 19
- 85
- 117
$("select[id=yourDropdownid] option:selected").text()
This works fine
![](../../users/profiles/1679775.webp)
- 4,684
- 3
- 29
- 36
For getting selected value use
$('#dropDownId').val();
and for getting selected item text use this line:
$("#dropDownId option:selected").text();
![](../../users/profiles/2424026.webp)
- 464
- 9
- 17
Select Text and selected value on dropdown/select change event in jQuery
$("#yourdropdownid").change(function() {
console.log($("option:selected", this).text()); //text
console.log($(this).val()); //value
})
![](../../users/profiles/904874.webp)
- 6,096
- 8
- 21
- 44
![](../../users/profiles/1390850.webp)
- 627
- 1
- 8
- 17
Try:
$var = jQuery("#dropdownid option:selected").val();
alert ($var);
Or to get the text of the option, use text()
:
$var = jQuery("#dropdownid option:selected").text();
alert ($var);
More Info:
![](../../users/profiles/5821456.webp)
- 988
- 11
- 20
var e = document.getElementById("dropDownId");
var div = e.options[e.selectedIndex].text;
![](../../users/profiles/5891501.webp)
- 1,103
- 13
- 28
-
I tried logging the div in `var div = e.options[e.selectedIndex].text;`, and it only displays the first option item. How to get each item to display? – Chris22 Aug 09 '17 at 06:59
-
@Chris22 refer this link https://stackoverflow.com/questions/3923858/jquery-getting-all-dropdown-values – Kalaivani M Aug 30 '17 at 17:00
Simply try the following code.
var text= $('#yourslectbox').find(":selected").text();
it returns the text of the selected option.
![](../../users/profiles/6349318.webp)
- 485
- 4
- 14
Use:
('#yourdropdownid').find(':selected').text();
![](../../users/profiles/63550.webp)
- 28,342
- 21
- 95
- 123
![](../../users/profiles/1677896.webp)
- 1,432
- 5
- 20
- 31
the following worked for me:
$.trim($('#dropdownId option:selected').html())
![](../../users/profiles/191647.webp)
- 18,338
- 35
- 143
- 207
-
1Note: Do not use this for multi select. It only grabs the first selected value. – max Mar 28 '16 at 04:25
In sibling case
<a class="uibutton confirm addClient" href="javascript:void(0);">ADD Client</a>
<input type="text" placeholder="Enter client name" style="margin: 5px;float: right" class="clientsearch large" />
<select class="mychzn-select clientList">
<option value="">Select Client name....</option>
<option value="1">abc</option>
</select>
/*jQuery*/
$(this).siblings('select').children(':selected').text()
This work for me:
$("#city :selected").text();
I'm using jQuery 1.10.2
![](../../users/profiles/4062955.webp)
- 151
- 1
- 4
$(function () {
alert('.val() = ' + $('#selectnumber').val() + ' AND html() = ' + $('#selectnumber option:selected').html() + ' AND .text() = ' + $('#selectnumber option:selected').text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="selectnumber">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
</div>
</form>
</body>
</html>
![](../../users/profiles/1192188.webp)
- 9,340
- 15
- 53
- 93
![](../../users/profiles/4847565.webp)
- 1,225
- 12
- 14
-
Hi how do you do this **inside a Table row/cell**, *how do you know which of the Dropdown from the table?* I am trying to make an ajax call to fetch and populate values, I can do this outside in a page, but not inside the Table Row... can you add some help please – Transformer Mar 12 '17 at 07:45
This code worked for me.
$("#yourdropdownid").children("option").filter(":selected").text();
![](../../users/profiles/683395.webp)
- 2,396
- 3
- 31
- 58
If you want the result as a list, then use:
x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})
![](../../users/profiles/1896222.webp)
- 7,861
- 15
- 70
- 115
$("#dropdown").find(":selected").text();
$("#dropdown :selected").text();
$("#dropdown option:selected").text();
$("#dropdown").children(":selected").text();
![](../../users/profiles/6783850.webp)
- 400
- 6
- 14
For multi-selects:
$("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }
![](../../users/profiles/854342.webp)
- 5,490
- 3
- 37
- 27
Try
dropdown.selectedOptions[0].text
function read() {
console.log( dropdown.selectedOptions[0].text );
}
<select id="dropdown">
<option value="1">First</option>
<option value="2">Second</option>
</select>
<button onclick="read()">read</button>
![](../../users/profiles/860099.webp)
- 53,729
- 20
- 259
- 241
$("#dropdownid option:selected").text();
if you use asp.net and write
<Asp:dropdownlist id="ddl" runat="Server" />
then you should use
$('#<%=ddl.Clientid%> option:selected').text();
![](../../users/profiles/6060168.webp)
- 824
- 1
- 12
- 26
Just add the below line
$(this).prop('selected', true);
replaced .att to .prop it worked for all browsers.
![](../../users/profiles/1770645.webp)
- 358
- 3
- 18
![](../../users/profiles/9328117.webp)
- 1,452
- 11
- 7