2016-07-27 7 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

関連する問題