1

I am a beginner in JavaScript. I am trying to program that present a table, and upon clicking on a cell it changes its content. this is what I tried to do:

<!DOCTYPE html>
<html>

<head>
  <style>
    table,
    td {
      border: 3px solid black;
    }
  </style>
</head>

<body>

  <table id="myTable">
    <tr>
      <td onclick="this.value ='Change 1';">cell 1</td>
      <td onclick="this.value ='Change 2';">cell 2</td>
    </tr>

  </table>

</body>

</html>

1 Answer 1

2

td doesn't have value property, you need to use innerHTML or textContent instead

<!DOCTYPE html>
<html>

<head>
  <style>
    table,
    td {
      border: 3px solid black;
    }
  </style>
</head>

<body>

  <table id="myTable">
    <tr>
      <td onclick="this.innerHTML ='Change 1';">cell 1</td>
      <td onclick="this.innerHTML ='Change 2';">cell 2</td>
    </tr>
  </table>

</body>

</html>

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

Comments

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.