2016-08-30 2 views
0

nth-childを使用して特定のtdをターゲットにしましたが、その特定のターゲットをターゲットにしたければ、後でリストを続けることができますそのnth-child、どうすれば可能でしょうか?nth-childをターゲットにしてからリストを続ける方法

var start = "3";  
var first = $("tr:first-child").find("td:nth-child("+start+")"); 

\\a function that allows me to go to the next td's that are after the third td (ignoring 1 & 2) 

答えて

2

selected-rowクラス:

var nextalltds = first.nextAll(); 
+0

これは、実際に他のすべての外に働きました。うまくやった! – Majo0od

0

あなたは要素の一致したセットから好きな要素を選択しfilter()機能を使用することができます。

これは私がこれまで持っているものです。次の例で

、第三の(インデックス= 2)のいずれかから始まるすべての行を検索し、追加するには、次の兄弟要素を標的とする .nextAll()セレクタを使用することができ

$('table').find('tr').filter(function(index) { 
 
    return index > 1; 
 
}).addClass('selected-row');
table { border-collapse:collapse } 
 
table td { 
 
    border:1px solid #333; 
 
    padding:5px 10px; 
 
} 
 
.selected-row td { background-color:#d8d8d8 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<table> 
 
    <tbody> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    <tr><td>Table cell</td><td>Table cell</td></tr> 
 
    </tbody> 
 
</table>

0

あなたは.next()を試しましたか?

var next = $("tr:first-child").find("td:nth-child("+start+")").next(); 

https://api.jquery.com/next/

0

あなたはこのように、:gtセレクタを使用することができます。

var start = "1"; // note: works on index, so to start on the third element, use 1 
 
var $first = $("tr:first-child td:gt(" + start + ")").addBack(); 
 
$first.addClass('foo');
.foo { color: #C00; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
    <tr> 
 
    <td>1</td> 
 
    <td>2</td> 
 
    <td>3</td> 
 
    <td>4</td> 
 
    <td>5</td> 
 
    </tr> 
 
</table>

関連する問題