How can I get the text within the selected dropdown menu option using jQuery?
I have tried:
var title = $("#selectattribute option:selected").text();
But I don;t think it works..
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you did should work:
Working example
Since it’s not working for you, the error must lie somewhere else. Maybe
#selectattributeis incorrect.To clarify some of the other answers, the
valueof an option is different from thetextinside it.For example:
Also, if no
selectedattribute is set in the HTML, the firstoptionwill be selected: