Retrieving Option Text from jQuery Drop-Down List
To obtain the text associated with a specific option tag in a jQuery drop-down list, use the following technique:
Option Based on Value
To get the text of an option with a specific value, even if it is not selected, employ the selector:
$("#list option[value='2']").text();
This selector matches the option tag that has the value '2' and retrieves its text content.
Selected Option
To get the text of the currently selected option, regardless of its value, utilize this selector:
$("#list option:selected").text();
This selector matches the selected option tag and extracts its text content.
Note that the initial approach of using $("#list[value='2']").text(); will not yield the desired result, as it attempts to find the entire
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3