Reputation: 5716
I know how to get the value of a selected option but i am wondering how to get its text.
this is how i access the option using the value ?
$('#dropdownId').children('option[value="'+5691+'"]').hide();
something like below,
$('#dropdownId').children('option[text="'+'some text'+'"]').hide();
Upvotes: 0
Views: 1161
Reputation: 1594
I guess you are trying to achieve some thing like this
if($('#dropdownId').children().text()=="some text")
$('#dropdownId').children().hide();
Thanks.
Upvotes: 0
Reputation: 7302
Try this:
HTML:
<select id="foo">
<option value="1">foo</option>
<option value="2">bar</option>
</select>
Java Script:
$(function () {
$("#foo").change(function(){
alert($("#foo option:selected").text());
});
});
Upvotes: 0
Reputation: 1720
Use .text()
.
Here's a fiddle - http://jsfiddle.net/friiks/XXsFy/
Upvotes: 1