2012-08-17 4 views
1

첫 번째를 제외한 모든 행의 HTML을 가져 오려는 테이블이 있습니다. 내가jQuery 처음부터 제외한 모든 행을 HTML로 가져 오는 방법은 무엇입니까?

$('#files-table> tbody > tr').not(':first').html() 

난 단지 2 행의 HTML을 얻을, 어디 제 3의 HTML을 사용

<table id="files-table"> 
    <tbody> 
      <tr> 
      <th class="text-left">Name</th> 
      <th>Type</th> 
      <th class="delete-th">Delete</th> 
      </tr> 
      <tr> 
      <td class="text-left"><label class="label-none">a.docx</label></td> 
      <td><label class="label-none">Manuscript</label></td> 
      <td><input type="checkbox" class="del-cb"></td> 
      </tr> 
      <tr> 
      <td class="text-left"><label class="label-none">test2.doc</label></td> 
      <td><label class="label-none">Manuscript</label></td> 
      <td><input type="checkbox" class="del-cb"></td> 
      </tr> 
     </tbody> 
</table> 

?

답변

2

html 메서드는 첫 번째로 일치하는 요소의 내용을 html 반환합니다.

일치하는 요소 집합의 첫 번째 요소의 HTML 콘텐츠를 가져옵니다. 일치하는 요소의 HTML 내용을

$('#files-table> tbody > tr').not(':first').each(function(){ 
    console.log($(this).html()) 
}) 

Fiddle

당신은 변수를 정의 할 수 있습니다 및 저장 :

당신은 each() 방법을 사용할 수 있습니다,이 시도

var html = ''; 

$('#files-table> tbody > tr:not(":first")').each(function(){ 
    html += $(this).html() 
}) 
1

왜냐하면 당신은 각 tr 객체를 통해 oping - 그래서 그것은 첫 번째 객체 인 두 번째 객체 만 반환합니다. tr

$('#files-table> tbody > tr').not(':first').each(function(){ 
    console.log($(this).html()); 
}); 
관련 문제