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>');
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.