2015-09-17 18 views
1

我無法選擇一組div中的所有最後一個輸入以及其中的表格。 Here's a jsFiddle of my issue.jQuery select:容器的最後一個孩子

的簡化版本我的HTML結構:

<div class=".container"> 
    <table> 
    <tbody> 
     <tr> 
     <td> <input /> </td> 
     <td> <input /> </td> <!-- last input in container --> 
     </tr> 
    </tbody> 
    </table> 
</div> 

<!-- More like this --> 
<div class=".container"> ... 

所以,如果我有5 .container所產生的選擇將有5 input

我嘗試了以下選擇:

$('.container input:last-child') 

回答

6

您可以選擇最後的td並獲得其子輸入,如:

var $inputs = $('.container td:last-child>input'); 

演示:https://jsfiddle.net/bonh4r0g/

+0

也可以使用:變量$輸入= $( '容器TD:最後的型>輸入。'); – EricL