-
How to get the selected text from dropdown using jquery
over 9 years ago
-
over 9 years ago
Hi Mayank,
You can get the selected text using following syntax.$("#yourdropdownid option:selected").text();
Often people confuse between text and val. So the difference is: .text() gives you the selected text what you are seeing on the dropdown. .val() gives you the value part in of the "option" element.
For Example:- If you write
$("#new-account-prefix option:selected").text();
you will get Mr.,Ms or whatever you select and see in the dropdown
But if you write$("#new-account-prefix option:selected").val();
you will get "mr","ms" etc as your result
1 Answer(s)