Reputation: 349
I am trying to modify the content of a particular column of a table whenever a cell is modified. The column is the one with the cell being modified in it.
Finding the index of the cell being modified in a particular row was quite straightforward. I found the table row and indexed it for the action.
But now I want to use that index to modify the column, including the trigger cell.
var childIndex = $this.closest('td').index(); // find index of trigger cell
var $allTableRows = $('tr'); // select all rows to index the particular cell
var aim = $allTableRows.children(childIndex); //search for target column here
I am making some mistake in passing the childIndex to the row-child criteria. Can someone please point out my mistake.
Thanks!
Upvotes: 0
Views: 100
Reputation: 1502
I think if you use the following you'll get what you want:
var targetColumnInAllRows = $('tr td:nth-child(' + (childIndex + 1) + ')');
Note that while the index is zero-based, nth-child
is one-based.
Upvotes: 2