2009-03-10 5 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