2013-08-19 51 views
-1

代碼:兩種:第n個孩子和:最後一個孩子

<table> 
    <tr> 
     <td></td> 
     <td></td> 
     <td></td> 
     <td colspan="2"></td> <==== Only this 
    </tr> 
    <tr> 
     <td></td> 
     <td></td> 
     <td colspan="3"></td> 
    </tr> 
    <tr> 
     <td></td> 
     <td></td> 
     <td></td> 
     <td></td> 
     <td></td> 
    </tr> 
</table> 

我只想選擇第四個「TD」,但只有當它的最後一次。我可以這樣做嗎?

tr td:last-child:nth-child(4) { /* Some Style */ } 
+5

這應該像你一樣工作。 – thirtydot

+1

是的,你可以:[** DEMO **](http://jsfiddle.net/K9TF8/) – MarcinJuraszek

+3

這是怎麼回事?要麼在發佈問題之前沒有嘗試自己的代碼,要麼通過簡化太多而將實際問題抽象出來。 – thirtydot

回答

1

是的,你可以

tr td:last-child:nth-child(4) { background: red; } 
-2

我想是不是possible.If你想那麼它的工作,你可以添加特定classid與你的願望td元素。

-2

試試這個

$("tr").each(function(){ 
    if($(this).find("td:nth-child(4)").is(':last-child')) { 
    $(this).find("td:nth-child(4)").css("color","red"); 
    } 
}); 

FIDDLE

+1

在這個問題上有一些看不見的jQuery標籤嗎? – thirtydot

0

您可以使用這樣demo

tr td:nth-of-type(4):last-child { 
    /*some code here*/ 
    } 

或者

tr td:nth-child(4):last-child { 
    background-color: red; 
    }