开发者

Replace the TD tag

I want to replace the <td> tag.

My code looks like this:

var divele = document.createElement("div");
divele.innerHTML = "<td><p>content</p></td>";

var tdele = document.getElementByd("tdid");
tdele.parentNode.replaceChild(divele.firstChild,tdele);

The tdid is replaced with the <p> tag content only not with the <td>.

When I assign the <td> content to the innerHTML of the <div>, the <td> is replaced from that content (as per the block level element).

How do I replace the <td> with the new <td开发者_运维技巧> content using innerHTML?


var td = document.getElementById('tdid');
td.innerHTML = "<p>content</p>";

simply put the content into the td directly.

replacing td cells can cause weird behaviour and will give you unexpected results if it works at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜