开发者

jQuery selector input select first and second

开发者 https://www.devze.com 2023-03-01 05:10 出处:网络
Right now I have two selects on my page: <div id=\"exportSelection\"> <select name=\"ddlRubrique\" id=\"\">

Right now I have two selects on my page:

<div id="exportSelection">
    <select name="ddlRubrique" id="">
        <option value=""></option>
        <option value="option1">option1</option>
    </select>

    <select name="_ddlSubRubrique" id="">
        <option value=""></option>
        <option value="option2">option2</option>
    </select>
</div>

I've been using this jQuery:

jQuery("#_ddlSubRubrique").c开发者_开发百科hained("#ddlRubrique");

but to make is more reliable i would like to tell the selector to select first select and select second select in this div #exportSelection.

How would you do that?


$("selector:eq(0),selector:eq(1)");


You can use .eq() and pass the 0-based index of the element:

var $selects = $('#exportSelection select');
// first: $selects.eq(0)
// second: $selects.eq(1)
0

精彩评论

暂无评论...
验证码 换一张
取 消