No products in the cart.
- This topic is empty.
-
AuthorPosts
-
July 9, 2015 at 2:00 am #9364
mhandzkie
ParticipantThis work for me:
$("#city :selected").text();
I’m using jQuery 1.10.2
September 17, 2015 at 5:13 am #9365mohammad-dayyan
Participantthe following worked for me:
$.trim($('#dropdownId option:selected').html())
November 19, 2015 at 5:36 am #9369sandeep-shekhawat
ParticipantSelect 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 })
January 23, 2016 at 9:07 am #9370mojtaba
ParticipantFor getting selected value use
$('#dropDownId').val();
and for getting selected item text use this line:
$("#dropDownId option:selected").text();
August 9, 2016 at 5:01 am #9361bhanu-pratap
Participant$(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>
January 4, 2017 at 12:53 pm #9367kalaivani-m
Participantvar e = document.getElementById("dropDownId"); var div = e.options[e.selectedIndex].text;
January 18, 2017 at 9:56 am #9359max
ParticipantIf you want the result as a list, then use:
x=[]; $("#list_id").children(':selected').each(function(){x.push($(this).text());})
March 9, 2017 at 7:03 am #9371vishal-thakur
ParticipantTry:
$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:
March 15, 2018 at 10:21 am #9358curtis-yallop
ParticipantFor multi-selects:
$("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }
May 21, 2018 at 11:01 am #9360manish-singh
Participant$("#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();
November 13, 2018 at 6:03 am #9372muddasir23
ParticipantSimply try the following code.
var text= $('#yourslectbox').find(":selected").text();
it returns the text of the selected option.
January 12, 2019 at 11:12 am #9357shahid-hussain-abbasi
ParticipantJust add the below line
$(this).prop('selected', true);
replaced .att to .prop it worked for all browsers.
December 17, 2019 at 6:50 am #9373shyamm
Participant$("#dropdown").find(":selected").text(); $("#dropdown :selected").text();
$("#dropdown option:selected").text();
$("#dropdown").children(":selected").text();
January 17, 2020 at 5:10 am #9362kamil-kielczewski
ParticipantTry
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>
February 13, 2020 at 4:17 am #9376naveenbos
ParticipantThis code worked for me.
$("#yourdropdownid").children("option").filter(":selected").text();
-
AuthorPosts
- You must be logged in to reply to this topic.