2011-04-06 3 views
3

을 받기 나는 내부 클래스 chrome-button와 컨트롤이 포함jQuery. 태그 + 클래스 이름

<table> 
    <tbody> 
     <tr> 
      <td> 
       <input name="price" class="chrome-input" /> 
      </td> 
      <td> 
       <button name="sellButton" class="chrome-button"> 
       </button> 
       <button name="priceButton" class="chrome-button"> 
       </button> 
      </td> 
     </tr> 
    </tbody> 
</table> 

가 어떻게 tr 얻을 수 HTML을 가지고있다.

$("tr").children('td').each(function(){ 
    $(this).children('.chrome-button').each(function(){ 
     alert($(this).html()); 
    }); 
}); 

답변

4
$(".chrome-button").closest('tr') 
+0

이것은 의사 선택기가 일반적으로 훨씬 느립니다. – Ben

4

이 시도 :이

alert($("tr+.chrome-button").html()); 
+0

감사합니다! 그 해결 된 작업. 교육을 위해, 내가 알고 싶습니다. 10 태그가있는 경우, 그 구문을 먼저 얻는 방법 $ ("tr : has (.chrome-button)") [0] .html() – Tuco

+0

tr DOM 요소를 usinn [0] 또는 .get (0) ... – Chandu

+0

$ ("tr : has (.chrome-button)"). eq (0) – Headshota