DEV Community

ishwar chandra tiwari
ishwar chandra tiwari

Posted on

how to get the contents of a table row

snippet to get tr DATA value

snippet to get td value

html +=
 ` <tr data-id=’JavaScript’>
 <td>1</td>
 <td>2</td>
 <td>3</td>
 <td>4</td>
 <td>5</td>
 </tr> `
 document.getElementById(‘tablebody’).innerHTML = html;

‘#example’).find(‘tr’).click(function() {

console.log(‘===========’, $(this).attr(“data-id”)); // get tr data value
console.log(‘===========’, $(this).data(‘id’));
console.log(‘===========’, $(this).find(‘td:eq(1)’).text()) // get 1st td value

});

Oldest comments (0)