Learn how to get the text of a select option using jQuery

jquery-theonlytutorials

This post teaches you how to get the text of a select option not the value actually!!

Its pretty simple in jQuery, Look at the below syntax:


$('#yourselectboxid :selected').text()

the above one line of code will give you the selected text (mind its not the value!!).

For your convenience i have written a demo snippet below:

<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function(){
$('#selectnumber').change(function(){
alert($('#selectnumber :selected').text());
});
})
</script>
</head>
<body>
<select id="selectnumber">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
</body>

 

Copy and paste the above script and test it yourself!

If you are looking for how to get the value of a select box CLICK HERE

2 thoughts on “Learn how to get the text of a select option using jQuery

Leave a Reply

Theme: Overlay by Kaira
Agurchand