DEV Community

ishwar
ishwar

Posted on

3

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

});

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs