Let's say I have a div called the_div
. In this div there will be multiple submit bu开发者_StackOverflow社区ttons. The submit buttons are added dynamically on the page.
<div id="the_div">
...other stuff
<input type='submit' value='Add'>
...other stuff
<input type='submit' value='Add'>
...other stuff
<input type='submit' value='Add'> -need to select this one
</div>
Is there a way I can use a jQuery selector to select the submit button that is closest to the end of the div? In the example above it would be the third submit button.
Use last.
$('#the_div :submit:last')...
$('#the_div').find('input:submit').eq(-1)
This will select the last submit inside #the_div
. eq()
gives you allot of control. If you want to select the first submit you can do eq(0)
, or before last you can do eq(-2)
Check working example at http://jsfiddle.net/cvcHf/
YOU CAN TRY LIKE THIS
$("#THE_DIV").closest() or $('#the_div').find('input:submit').eq(':last');
PLEASE LET ME KNOW IF IT WAS NOT WORKING.. TH
精彩评论