I have a table with users and want the action buttons to work on the <tr> they are children of. When one of the buttons calls a javascript function, I want the function to store the <tr> element in a variable so I can work with just the one that holds the button and not affect any other <tr> elements. ps: I can use jQuery!
My code:
function editUser() {
/*
var button = *the button clicked*;
var tr = button.getParent(get the <tr> in some way);
editSomething(tr);
*/
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(even) td {
border: 1px solid #cbcbcb;
}
#search {
padding-bottom: 5vw;
}
.actionLink {
border: 1px solid black;
padding: 2px;
}
.actionLink:hover {
cursor: pointer;
background-color: black;
color: white;
}
<table>
<thead>
<tr>
<th>Id</th>
<th>Username</th>
<th>Rank</th>
<th>Points</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Gamanware</td>
<td>Owner</td>
<td>0</td>
<td>Online</td>
<td>
<a onclick="editUser()" class="actionLink">Quick Edit</a>
<a onclick="editUser()" class="actionLink">View</a>
<a onclick="editUser()" class="actionLink">Delete</a>
</td>
</tr>
</tbody>
</table>