NeverGiveUp NeverGiveUp - 4 months ago 16
HTML Question

How to hide parent's parent element with JavaScript?

I have this code , I want when the button 'Accept' is clicked , the whole

<tr>
tag to be hidden by the style 'display:none;'. at the moment , the button hides the
<td>
and I don't want it to be like that. I want it to hide the whole table row.

<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@gmail.com</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>

Answer

Just do this:

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