Reputation: 1159
I am trying to something very simple. I have this select tag
<select id="appID">
<option value="1409608204102">test app 1</option>
<option value="1409608295422">test set 2</option> </select>
I want to print the text of the selected option in the "printHere" div. Very simple but for some reason I cant figure out how to do it through jquery
I am doing this but
$('#appID').change(function(){
var k = $(this).is('selected','selected').text();
$('.printHere').text(k);
});
Upvotes: 2
Views: 89
Reputation: 330
Just adding what the other posters have said into a working example for you. http://jsfiddle.net/kshreve/P6qbp/2/
var k = $(this).find(':selected').text();
$("div").text(k);
Upvotes: 0
Reputation: 79830
Try using :selected
,
var k = $(this).find(':selected').text();
Upvotes: 1
Reputation: 382132
You can use
var k = $(':selected', this).text();
k
will be "test app 1"
or "test set 2"
.
Upvotes: 4