2013-06-14 1 views
0

도와주세요.<td>의 id 속성을 얻으려면 jQuery에서 <tr>을 얻으시겠습니까?

루핑 대신 .. 첫 번째 ID 또는 두 번째 ID를 얻는 것과 같은 것이 있습니까?

예 :

"<tr class='test_point' id="+fileName+"><td><img src='"+ROOT_PATH+"/assets/diamond.png' /><td class='test_point_name' id="+test_point_id+">"+test_point 

+"</td></tr>" 

each 문에 대한 당신의 선택은 조금 떨어져입니다

$(#fileName).each(function(index){ 
    console.log(index + ": " + $(this).text()); 
    //console.log("id_value: "+$(this).attr('id')); 
    console.log("test_value: "+ $(this).find('td').attr('id')) 
} 
+0

'$ (# fileName) .find ('td'). 각각 (function (index) {'당신이'.find ('td')'를 잊었거나'.children ('td')'를 사용했다. – Omar

+0

동일한 ID를 가진 여러 요소? 선택자에 따옴표가 없습니까? 닫지 않음')'? 출력을 받고 있습니까? –

+0

코드를 '

' (으)로 포장 하시겠습니까? 그것이 없으면 아무것도 작동하지 않을 것입니다. 이것을 확인하십시오 http://jsfiddle.net/Palestinian/rgNP7/ – Omar

답변

1

인덱스하여 항목의 id를 얻으려면이를 사용합니다.

$('#fileName').find('td')[0].id; 

[0] 먼저 수단

Demo

등등 .. 그리고 [1]초.

+0

고마워요. :). 이 작업은 td에 대해 반복적으로 수행되었습니다. – Vinay

+0

@ 비니 당신을 환영합니다 :) – Omar

0

여기 ID로 TR을 가져 오는. 당신은 따옴표를 놓치고 :

$("#fileName").each(function(index){ 

을 아니면 어떤 경우 변수를 fileName

$("#" + fileName).each(function(index){ 

을 사용하고 싶었, ID의는 고유해야합니다. 당신이 당신의 tr의 클래스를 사용하고자하는 추측 임 :

$(".test_point").each(function(index){ 
0
$('#your-tr-id-here').each(function() { 
    $(this).children('td').each(function() { 
     console.log('td ID: ' + $(this).attr('id')); 
    }); 
}); 
관련 문제