Open In App

How to get text value of a selected option in jQuery ?

Last Updated : 25 Aug, 2021
Like Article

Introduction: In this article, we will see how we can use jQuery to get the text value from the selected option. While working on some form-related user interface, we often use the select option, and to use that, we will surely need those values that are being selected.

Approach: We will use select option is a very easy method to make a drop-down menu and the val() method that is an inbuilt method in jQuery which is used to returns or set the value of attribute for the selected elements. This method apply on the HTML form elements.



Parameters: This method does not accepts any parameters.


jQuery CDN Link: Add the following code in the head tag of the HTML file.

<script   src=”” integrity=”sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=”   crossorigin=”anonymous”></script>

Example: In this example, we will make a select option element and print values on the browser console that is getting selected by the user using val() method as described above.


<!DOCTYPE html>
<html lang="en">
    <select id="selectVal">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
        <option value="4">Four</option>
        <option value="5">Five</option>
        // It will print the selected value
        function displayNum() {
        // When the selected value will change,
        // the above function is called


get selected value

Now we have an idea of how to get those values, so we can use those values and use it wherever we want, we are not limited to the console only.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads