jQuery selector input select first and second
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)
精彩评论