skip to Main Content
$(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


  1. table td does not have any attribute value. You can try using innerText

    var col1 = currentRow.find("td:eq(0)").innerText;

    Login or Signup to reply.
  2. 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:

    currentRow.find("td:eq(0)").text();
    

    Docs: https://api.jquery.com/text/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search