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
Release: 2024-10-28 07:45:02
Original
507 people have browsed it

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();
Copy after login

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();
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template