Reputation: 173
I am having this on my client side console
I want to extract only 2015 which is currently selected option. How is it possible?
Upvotes: 1
Views: 47
Reputation: 1493
EDITED
According to this link,
$( "#YearIn option:selected" ).text();
This should do.
Upvotes: 2
Reputation: 53958
You could try this:
var selectedOptionText = $("YearIn option:selected").text();
For instance check the following snippet:
$(function(){
$("#YearIn").change(function(){
alert($("#YearIn option:selected").text());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="YearIn">
<option val="1">One</option>
<option val="2">Two</option>
<option val="3">Three</option>
<option val="4" selected>Four</option>
<option val="5">Five</option>
</select>
Upvotes: 3