开发者

Replace the TD tag

开发者 https://www.devze.com 2022-12-10 20:35 出处:网络
I want to replace the <td> tag. My code looks like this: var divele = document.createElement(\"div\");

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

精彩评论

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