Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get label value from dropdown

Tags:

jquery

I know I can get the value using $("#dropdown").val()

does anybody know how i get the label?

Cheers

like image 530
jim smith Avatar asked Oct 01 '10 12:10

jim smith


3 Answers

var text = $("#dropdown").find("option:selected").text();

which is the same as

var text = $("#dropdown option:selected").text();
like image 160
mkoryak Avatar answered Nov 26 '22 12:11

mkoryak


All these answers fail to answer the question. He's talking about the label, not the text. Label is a valid attribute of the option (Specifies a shorter label for an option). See http://www.w3schools.com/tags/tag_option.asp

To get the label use: $('#dropdown').find("option:selected").attr('label')

like image 24
bicycle Avatar answered Nov 26 '22 10:11

bicycle


Use the :selected selector (to get the selected <option>) and get the .text(), for example:

$("#dropdown :selected").text()
like image 39
Nick Craver Avatar answered Nov 26 '22 10:11

Nick Craver