I want to get each cell value from an HTML table using JavaScript when pressing submit button.
How to get HTML table cell values?
To get the value of the clicked cell, the jQuery solution is to attach a click event to all the table cells and assign the highlight CSS to the clicked cell and obtain its value. Then show this value on the screen by assigning it to the span element.
$('#mytable tr'). each(function() { var customerId = $(this). find("td:first"). html(); });
jQuery: code to get TD text value on button click. text() method we get the TD value (table cell value). So our code to get table td text value looks like as written below. $(document). ready(function(){ // code to read selected table row cell data (values).
To get the text from this cell-
<table> <tr id="somerow"> <td>some text</td> </tr> </table>
You can use this -
var Row = document.getElementById("somerow"); var Cells = Row.getElementsByTagName("td"); alert(Cells[0].innerText);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With