Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a value from second element of a class with jquery?

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 ?

like image 731
mirza Avatar asked Dec 04 '22 04:12

mirza


1 Answers

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].

like image 188
Felix Kling Avatar answered Jan 05 '23 04:01

Felix Kling