2016-07-27 6 views
0

나는이 코드를 가지고 있는데, 'Accept'버튼을 클릭하면 전체 <tr> 태그가 'display : none;'스타일로 숨겨지기를 원한다. 지금은 버튼이 <td>을 숨기고 있기 때문에 나는 그런 식으로하고 싶지 않습니다. 전체 테이블 행을 숨기고 싶습니다.JavaScript로 부모의 부모 요소를 숨기는 방법은 무엇입니까?

<table class="table table-bordered"> 
    <tr> 
    <th>Name</th> 
    <th>Username</th> 
    <th>Email</th> 
    <th>Skype</th> 
    <th>Phone</th> 
    <th>Message</th> 
    <th>Accept?</th> 
    </tr> 
    <tr style=""> 
    <td>Name</td> 
    <td>Username</td> 
    <td>[email protected]</td> 
    <td>skypename</td> 
    <td>phone</td> 
    <td>MESSAGE</td> 
    <td><button onclick="this.parentElement.style.display='none';" class="btn btn-success">Accept</button> <button class="btn btn-danger">Deny</button></td> 
    </tr> 
</table> 
+2

jQuery를 태그를 사용하지 마십시오을 그것을 사용하지 마십시오 –

+0

'this.parentElement.parentElement.style.display = 'none''? –

+1

'.parentElement'가 버튼에서'td'로 당신을 가져 오면'td'에서'tr'까지 어떻게 얻을 수 있다고 생각합니까? –

답변

1

그냥이 어떻게이 방법으로 수행 할 수 분명히 당신이 경우

<button onclick="this.parentElement.parentElement.style.display='none';" class="btn btn-success">Accept</button> 
+0

고마워요. 그것은 작동합니다. – NeverGiveUp

0

당신이 jQuery를 언급 한 이후로 당신은 그것을

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table class="table table-bordered"> 
 
     <tr> 
 
     <th>Name</th> 
 
     <th>Username</th> 
 
     <th>Email</th> 
 
     <th>Skype</th> 
 
     <th>Phone</th> 
 
     <th>Message</th> 
 
     <th>Accept?</th> 
 
     </tr> 
 
     <tr style=""> 
 
     <td>Name</td> 
 
     <td>Username</td> 
 
     <td>[email protected]</td> 
 
     <td>skypename</td> 
 
     <td>phone</td> 
 
     <td>MESSAGE</td> 
 
     <td><button onclick="$(this).parents('tr').hide()" class="btn btn-success">Accept</button> <button class="btn btn-danger">Deny</button></td> 
 
     </tr> 
 
    </table>

+0

'table' 태그를 숨기지 않습니까? OP는'tr' 태그를 숨기려고합니다. –

+0

예, 테이블 태그를 숨 깁니다. 나는 그것을 원하지 않는다. 요소가 들어있는 현재 태그를 숨길 필요가 있습니다. – NeverGiveUp

+0

업데이트 된 코드를 확인할 수 있습니다 – Kld

관련 문제