0

I need to change the eq(0) and eq(6) values to itemRow and itemCol values.

var itemRow = element.parentNode.parentNode.rowIndex;
var itemCol = element.parentNode.cellIndex;

$('#tblItem tbody tr:eq(0) td:eq(6)').text("0.00");

This is my current code but it's not working:

$('#tblItem tbody tr:eq(' + itemRow + ') td:eq(' + itemCol + 1 + ')').text("0.00");

1 Answer 1

1

You need to wrap itemCol + 1 in parentheses so it's processed before the concatenation:

$('#tblItem tbody tr:eq(' + itemRow + ') td:eq(' + (itemCol + 1) + ')').text("0.00");

var itemRow = 1; //element.parentNode.parentNode.rowIndex;
var itemCol = 0; //element.parentNode.cellIndex;

$('#tblItem tbody tr:eq(' + itemRow + ') td:eq(' + (itemCol + 1) + ')').text("0.00");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tblItem">
  <tbody>
    <tr>
      <td>a</td>
      <td>b</td>
    </tr>
    <tr>
      <td>c</td>
      <td>d</td>
    </tr>
  </tbody>
</table>

Sign up to request clarification or add additional context in comments.

3 Comments

It worked, can't believe I didn't think of enclosing that to a parenthesis. Thanks man! I'll tag this as accepted once the counter for tagging the answer finishes
No problem, glad to help.
Awesome username, by the way :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.