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 ?
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].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With