Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add td after a td

I have a td and I want to add a new one, but my new td is shown as text on my page, what am I missing
my code :

        var firstTd = parent.document.getElementById("currentTd");           
        firstTd.after('<td><span>teste</span></td>');

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

See the documentation:

The Element.after() method inserts a set of Node or string objects in the children list of the Element’s parent, just after the Element. String objects are inserted as equivalent Text nodes.

So pass an element instead.

const firstTd = parent.document.getElementById("currentTd");           
const secondTd = document.createElement('td');
const span = document.createElement('span');
span.textContent = "teste";
secondTd.appendChild(span);
firstTd.after(secondTd);

or consider insertAdjacentHTML

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading