2014-01-21 25 views
0

HTML看起來像這樣首先選擇對象,其中家長不上課

<tr class="rowinactive"> 
<td> 
<div class="controllingbuttons"> 
<a title="Aanpassen" href="/2013-2014/Persoon/Edit/1811?instID=410"> 
<img width="16" alt="Edit" src="/img/pencil.png"> 
</a> 
... 
</td> 
</tr> 

OR

<tr> (rowinactive class missing) 
<td> 
<div class="controllingbuttons"> 
<a title="Aanpassen" href="/2013-2014/Persoon/Edit/1811?instID=410"> 
<img width="16" alt="Edit" src="/img/pencil.png"> 
</a> 
... 
</td> 
</tr> 

現在,我要算在第一個div圖像數量「controllingbuttons」,但它的父級TR不能有'rowinactive'類。

我的代碼以前(當我沒有在意rowinactive還)

$(".controllingbuttons").first().parent("td").find("img").length 

我一直想這一點,但它不工作:

$(".controllingbuttons").not($(".controllingbuttons").parents(".rowinactive").find(".controllingbuttons")).first().parent("td").find("img").length 

什麼想法?

回答

2
$('tr').not('.rowinactive').find('.controllingbuttons img').length 
+0

我覺得'$('tr')。not('。rowinactive')。find '.controllingbuttons img')。length'將會做,或者最壞的情況是''('tr')。not('。rowinactive')。find('.controlbuttons')。first('img')。length'' –

+0

@ArunPJohny是的,就是這樣。 – xdazz

+0

我確實需要First()。謝謝! – Stefanvds

1

嘗試使用closest():not()一起:

$(".controllingbuttons").closest('tr:not(.rowinactive)').length 
1

你可以試模本:

var imageLen = $(".controllingbuttons").closest('tr:not(.rowinactive)').each(function(){ 
    return $(this).find('img').length; 
}); 
0

$( 「controllingbuttons」)父('TR:沒有(。 rowinactive)')。first()

or

$(「。controlsbuttons」)。closest('tr:not(.rowinactive)td:First')。長度