How to get selected text or value of dropdown in Jquery?
I have a dropdown as below, it has selected default value, now I want to get both value and text of that selected item.
<select id="myselect"> <option value="1">One</option> <option value="2">Two</option> <option selected value="3">Three</option> <option value="4">Four</option> <option value="5">Five</option> </select>
It will return value = 3 and text = Three. How can I do it?
Oh, it is easy to do if you are using Jquery.
Jquery support two methods for you to get text and value option selected, they are text() and val().
1. To get text using text() method.
var textSelected = $("#myselect option:selected").text(); // return Three
2. To get value using val() method.
var valSelected = $("#myselect option:selected").val();
:selected: this is a selector help get the current option selected.
You can see an example code here.Sandeep Kumar May 14 2020