How to determine the content of the first cell in the table when you click on any cell in the row?
- @ florian92, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Vitalina
|
1 answer
Are you on pure JS? Then you can:
var td = document.querySelectorAll('#tbl td'); [].forEach.call(td, function(el){ el.addEventListener('click', function(){ console.log(this.parentNode.firstElementChild.innerHTML); }, false); }); With jQuery like this:
$('#tbl td').on('click', function(){ console.log($(this).closest('tr').find('td:first').text()); }); |