$(document).on("click", ".add", function() {
// get the current row
var currentRow = $(this).closest("tr");
var col1 = currentRow.find("td:eq(0)").text(); // get current row 1st table cell TD value
var col2 = currentRow.find("td:eq(1)").text(); // get current row 2nd table cell TD value
var col3 = currentRow.find("td:eq(2)").text(); // get current row 3rd table cell TD value
alert(col3);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tr>
<td data-label="Id">Item ID</td>
<td data-label="Amount">Amount</td>
<td data-label="Buyer" id="qwe">Buyer</td>
<td data-label="Items">Items</td>
<td data-label="Email">Email</td>
<td data-label="Actions">
<a class="add" title="Add" data-toggle="tooltip"><i class="material-icons">ADD</i></a>
<a class="edit" title="Edit" data-toggle="tooltip"><i class="material-icons">edit</i></a>
<a class="delete" title="Delete" data-toggle="tooltip"><i class="material-icons">delete</i></a>
</td>
</tr>
2
Answers
table
td
does not have any attributevalue
. You can try usinginnerText
var col1 = currentRow.find("td:eq(0)").innerText;
Hard to determine without seeing your DOM structure. Or clear question. But to get the text of that
<td>
including it’s children, you could use.text()
Example:
Docs: https://api.jquery.com/text/