Alex
Alex

Reputation: 7688

jQuery get curent select's text

How can I get the current <select> text? I mean if I have selected the <option name="me">ME</option> how can I get its text?

Because the way I'm trying, returns all the texts inside the <select>

$('#action').change(function() {

    console.log($(this).text()); //this returns all the texts inside select

Upvotes: 1

Views: 72

Answers (3)

user1538943
user1538943

Reputation:

$("#" + $(this).attr("id") + " option:selected").text();

would work as well! But please use danish's solution!

Upvotes: 2

danish hashmi
danish hashmi

Reputation: 484

try this

$('#action').change(function() {

    $(this).find(':selected').text(); 
});

Upvotes: 3

Clyde Lobo
Clyde Lobo

Reputation: 9174

You can get the text of a select by using

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

Upvotes: 0

Related Questions