如何使用jQuery选择最接近给定div末尾的特定元素?

如何使用jQuery选择最接近给定div末尾的特定元素?,jquery,jquery-selectors,Jquery,Jquery Selectors,假设我有一个div,名为the\u div。在此div中,将有多个提交按钮。在页面上动态添加提交按钮 <div id="the_div"> ...other stuff <input type='submit' value='Add'> ...other stuff <input type='submit' value='Add'> ...other stuff <input type='submit' v

假设我有一个div,名为
the\u div
。在此div中,将有多个提交按钮。在页面上动态添加提交按钮

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

…其他东西
…其他东西
…其他东西
-需要选择这个吗
有没有一种方法可以使用jQuery选择器来选择距离div末尾最近的submit按钮?在上面的示例中,它将是第三个提交按钮

$('#the_div').find('input:submit').eq(-1)
这将选择
#div
中的最后一次提交
eq()
为您分配控制权。如果要选择第一次提交,可以执行
eq(0)
,或者在最后一次提交之前执行
eq(-2)

检查工作示例 这将选择
#div
中的最后一次提交
eq()
为您分配控制权。如果要选择第一次提交,可以执行
eq(0)
,或者在最后一次提交之前执行
eq(-2)

检查使用中的工作示例

$('u div:submit:last')…
使用

$('u div:submit:last')…

您可以这样尝试

$("#THE_DIV").closest() or $('#the_div').find('input:submit').eq(':last');
如果它不起作用,请告诉我。。你可以这样试试

$("#THE_DIV").closest() or $('#the_div').find('input:submit').eq(':last');
如果它不起作用,请告诉我。。TH