How to get the selected value of a dropdown item using jQuery?
Method 1:
let selectedValue = $('#element_id option:selected').val();
Example:
var roleId = $('#ddlRole option:selected').val();
alert('Selected Role Id is: ' + roleId);
Method 2:
let selectedValue = $('#element_id').val();
Example:
var roleId = $('#ddlRole').val();
alert('Selected Role Id is: ' + roleId);
Output:
Demo: https://jsbin.com/kakaxazudo/1/edit?html,output
-
CreatedJan 17, 2020
-
UpdatedNov 03, 2020
-
Views1,600
Related Articles
.prop() vs .attr() in jquery
How to get the selected text of a dropdown item using jQuery?
How do I check whether a checkbox checked in jQuery?
Setting “checked” for a checkbox in jQuery?
How to check if an element exists in jQuery?
Set DropDownList value based on text/value in jQuery
Get selected text/value from DropDownList (or) Select in jQuery
Get selected index from DropDownList (or) Select in jQuery
Clear items from DropDownList (or) Select in jQuery.
How to replace string in JQuery?