<tr>
<td>Sample Data</td>
<td>2020</td>
<td>75</td>
<td>05-20-2018</td>
<td><a href="#" class="delete-item secondary-content"><i class="fa fa-trash"></i></a></td>
</tr>
In my table, there is a row with the data presented above. I would like to extract the first value in the row, which is "Sample Data", when the <i>
element is clicked.
The rows are contained within a div with the ID of #list
.
del(target,title) {
if (target.className === 'fa fa-trash') {
// To access and compare this title in LocalStorage for deletion purposes
}
}
document.getElementById('list').addEventListener('click', function (e) {
const tr = e.target.parentElement.parentElement.parentElement;
console.log(tr);
del(e.target, title);
});
The output displayed on the console will be:
<tr> <td>Sample Data</td> <td>2020</td> <td>75</td> <td>05-20-2018</td> <td><a href="#" class="delete-item secondary-content"><i class="fa fa-trash"></i></a></td> </tr>
How can I locate the first <td>
from this point without utilizing jQuery?