Brian J Brian J - 4 months ago 17
HTML Question

How to return table row data on click of row td?

I'm trying to return the row data as an array when I click a button on that table row. Searching on SO gave me this example using

But when I run the web app and click a the success button on any of the table rows, the array returned in the console is empty.

enter image description here

I've verified that each table row contains data so I'm not sure why no data is returned using the map function.

I also know that the function is firing on click of the buttons with


How to return table row data on click of row td?

This is the gist of the table and the associated jQuery function to map the row data:

<table id="statusTable" class="table table-hover table-bordered results">
<th style="visibility:hidden;" >ID</th>
<th>IT Owner</th>
<th>Update Record</th>

@foreach (var row in Model.ReleaseStatus)
<td style="visibility:hidden;" >@Html.Raw(row.ID)</td>
<td id="app_name" class="links" style="font-size: 14px;">@row.ID</td>
<td><button type="submit" class="btn btn-success btn-lg">Update</button></td>


JQuery function:

$(".btn-success").click(function () {
var tableData = $(this).children("td").map(function () {
return $(this).text();



You need to find tr, then tds



        <td>col #1</td>     
        <td>col #2</td>
            <button type="button">click me</button>


$("button").click(function() {
    var $td = $(this).closest('tr').children("td"),
        len = $td.length;       

    var tableData = $ {   
        if(i < len -1)
            return $(this).text();

    console.log(tableData); // ["col #1", "col #2"]