Reputation: 5793
my html code:
<select class="b_selectbox">
<option value="0">Status</option>
</select>
<select class="b_selectbox">
<option value="0">Type</option>
</select>
<select class="b_selectbox">
<option value="0">Category</option>
</select>
That's working for first element:
$(".b_selectbox option:first").text();
I am trying to get text "Type", here is what i tried so far:
$(".b_selectbox option:first").text()[1]; // result: "t" probably second letter from "Status"
$(".b_selectbox option:first")[1].text(); // not working either
Is there a solution without using each and id names ?
Upvotes: 8
Views: 13693
Reputation: 816334
Either
$('.b_selectbox option').eq(1).text();
if each select element has only one option (makes a select
unnecessary?), or if you want to get the second of all options, or
$('.b_selectbox').eq(1).children('option').first().text();
if you want the text of the first option
of the second select
element.
For more information, see .eq()
[docs].
Upvotes: 20
Reputation: 79830
I think you are looking for :eq operator... Try,
$(".b_selectbox:eq(1) option:first").text()
Upvotes: 3