2012-05-05 56 views
0
<div class="one"> 
    <div class="two"> 
     <div class="three">success</div> 
    </div> 
</div> 

如果我點擊第三div,例如$(.three).click(function(){ }); 我需要的類的父div.one)的。我怎麼能在jQuery中做到這一點?如何通過使用第三個子類獲取父級div值?

+0

refff http://stackoverflow.com/questions/545978/finding-the-id-of-a-parent-div-using-jquery – Dgo

回答

1

您可以試用.parent().parent(),例如, $(".three").parent().parent().anything(...)

1

一般的解決辦法是:

$(this).closest(".outer"); 

這樣:

$(".anyDepth").click(function() { 
    $(this).closest(".outermostDiv").addClass("foo"); 
}); 
+0

THANKS BUDDIES我期待UR繼續提供服務 –

相關問題