jQuery Get Selected Option from Dropdown
jQuery Get Selected Option from Dropdown
529
31-Jul-2023
Updated on 01-Aug-2023
Aryan Kumar
01-Aug-2023Sure, here is how to get the selected option from a dropdown using jQuery:
JavaScript
The
selectElementvariable will contain the reference to the dropdown element. Theoptionsproperty of theselectElementvariable will contain an array of objects, where each object represents an option in the dropdown list. Thevalueproperty of each object will contain the value of the option.The
selectedIndexproperty of theselectElementvariable will contain the index of the selected option. Theoptions[selectElement.selectedIndex]will return the object that represents the selected option.The
valueproperty of the selected option object will contain the value of the selected option.Here is an example of how to use this code:
JavaScript
This code will create a dropdown list with three options. When the user selects an option from the dropdown list, the value of the selected option will be displayed in the console.