2009-03-10 11 views
1

内の要素を選択:jQueryの:既に選択された要素例えば

$("table tr").click(function(event) 
{ 
    //Say, here i want get the data of td element where its class name="special" 
}); 

、私は要素を選択することができますどのような方法がありますが、クリックイベント、上記の添付要素の下の要素($(」でテーブルtr "))?

答えて

4

を動作することを考えて

$(this).find(".special").html(); 

のように、あなたがこれを行うことができます:

$("table tr").click(function(event) 
{ 
    $(this).children('td.special').whatEverYouNeed(); 
}); 

は、一般的に言えば、あなたはfind()を使用する必要があります。

$("table tr").click(function(event) 
{ 
    $(this).find('td.special').whatEverYouNeed(); 
}); 
+1

'$( 'td.special'、this)'を使うこともできます。これはセレクタのスコープをコンテナ 'this'に限定します – Jimbo

2

何か、私はそれがこの特定のケースで

+0

おかげで男!出来た! :) – Saneef

関連する問題