2017-11-13 8 views
0

그래서 이상하게 들릴 지 모르지만 표의 행 "Product Name"에서 문구를 검색하려고합니다. 내가 잘못 뭐하는 거지jquery로 숨기기 테이블 행에 텍스트가 포함되어있는 경우 Qty 필드

var thebook = $("tr:contains('Product Name')"); 
jQuery(thebook).children(input[title='Qty']).hide(); 

: 그것을 발견했을 때 나는

여기

내가 뭘하려 (마다 다를 수 있습니다 id)를 title="Qty"과 필드를 숨기려는?

+0

올바른로 답을 선택하시기 바랍니다가 있도록 당신을 위해 작동하는 경우 다른 사람들도 같은 문제에 직면 할 수 있습니다. –

답변

1

input[title='Qty'] 내가 다른 문제가되지 않습니다 확신 할 수 없다, 전체 코드를 보지 않고 "input[title='Qty']"

처럼 따옴표 수 있지만 여기에 내가 .children()보다는 .find()을 사용하는이 작업의 예해야 후손 체인에 모든 방법을 검색하려면 :

$("tr:contains('Product B')").find("input[title='Qty']").hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
    <tr> 
 
    <td>Product A</td> 
 
    <td>Quantity: <input title='Qty'></td> 
 
    </tr> 
 
    <tr> 
 
    <td>Product B</td> 
 
    <td>Quantity: <input title='Qty'></td> 
 
    </tr> 
 
    <tr> 
 
    <td>Product C</td> 
 
    <td>Quantity: <input title='Qty'></td> 
 
    </tr> 
 
</table>

+0

또는 .children() 대신 .find()를 사용하여 하위 체인 전체를 검색 할 수 있습니다. – emshore

+0

코드 스 니펫을 업데이트해야보다 효율적으로 접근 할 수 있습니다. –

+1

감사합니다. @MuhammadOmerAslam -이보다 효율적인 접근 방법을 반영하기 위해 업데이트 된 답변입니다. – emshore