I have this HTML:
<select class="business_types_select" name="business_type_id">
<option value="0" selected="selected">Select a Business Type</option>
<option value="54">Bakery</option>
<option value="55">Tobacco</option>
</select>
and if I select Bakery and then try:
$(".business_types_select").val()
I get 54, but how do i get the text Bakery? If I try
$(".business_types_select").text()
I get:
" Select a Business Type Bakery Tobacco "
Try:
Without this, the
.text()is behaving like it should, which is to bring back all of the text from that particular class. Adding:selectedto the selector narrows it down to just the one you have selected.Remember to cache your selectors if you’re going to be operating on them often for performance.