By clicking on the button in the cell, you need to send the values ​​of the other cells of the same row to the modal form. I found some kind of code, it even outputs something. But what it does and how I get what I need - alas, I don’t know. Tell me what to google to understand what is happening in the script? Or explain what is happening. All the hands in any way will not reach the study of javascript and the task set must be completed.

there is such a markup:

<table id="checked-table" class="table table-bordred table-striped" align="center"> <thead> <tbody> <tr> <td><input type="checkbox" class="checkthis" /></td> <td>0</td> <td>1</td> <td>2</td> <td width="20" align="center"> <p data-placement="top" data-toggle="tooltip" title="Edit"> <button class="btn btn-primary btn-xs" data-title="Edit"> <span class="glyphicon glyphicon-pencil"></span> </button> </p> </td> </tr> </tbody> </thead> </table> 

and there is a code:

 $('.btn.btn-primary').click(function(){ var tdVals = $(this).parent('td').siblings('td').map(function(i, td){ return $(td).text(); }) console.log(tdVals); }); 
  • You need to fix $ (this) .parent to $ (this) .parents. And everything will be simple .... Choose the pressed button, select its parent with the td tag, take all the neighbors with the td tag from it, and for each element from such a set, return its contents as text ... - sepgg

1 answer 1

You can do it like this ( https://api.jquery.com/closest/ ):

 $('.btn.btn-primary').click(function(){ var tdVals = $(this).closest('tr').find('td').map(function(i, td) { return $(td).text(); }); console.log(tdVals); }); 

If you don’t need to get the value of the cell where the button is located, you can add a class to the td element, for example, exclude and replace the selector in the find method:

 var tdVals = $(this).closest('tr').find('td:not(.exclude)').map( /* ... */ );