0

I have this HTML code, and I want to change the table td content (with new content instead of Old content) using Javascript. How can I do it?

    <table>
    <tr>
    <td><label class='A' >A:</label> </td>
    <td class='myClass'/>Old Content</td> 
    </tr>
    </table>
1
  • What have you already, and can you give an example of the output? Commented Feb 24, 2017 at 8:55

1 Answer 1

1

Trivial:

var element = document.querySelector('.myClass')

// If your content contains only text:
element.textContent = 'New Content'

// If your content contains more complicated tags:
element.innerHTML = '<strong>New Content</strong>'
<table>
  <tr>
    <td><label class="A">A:</label></td>
    <td class="myClass">Old Content</td>
  </tr>
</table>

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.