Home >Web Front-end >JS Tutorial >How to Get Option Text in a Drop-Down List Using jQuery?

How to Get Option Text in a Drop-Down List Using jQuery?

Barbara Streisand
Barbara StreisandOriginal
2024-10-28 07:45:02495browse

How to Get Option Text in a Drop-Down List Using jQuery?

Recovering Option Text Using jQuery

To obtain the text of a specific option element within a drop-down list, employ the following jQuery selector:

Targeting a Specific Option by Value:

To retrieve the text of an option having a specific value, use the following:

$("#list option[value='2']").text();

In this example, we are targeting the

Retrieving the Selected Option's Text:

To obtain the text of the currently selected option, employ the following selector:

$("#list option:selected").text();

In this scenario, we are targeting the

The above is the detailed content of How to Get Option Text in a Drop-Down List Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn