最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html table - Create a paragraph in javascript - Stack Overflow

programmeradmin1浏览0评论

I use the following code in javascript to replace a table content on a click button, but I want to add another paragraph and between them an image.

function changeContent() {
    var x = document.getElementById('Table').rows;
    var y = x[0].cells;
    y[0].innerHTML = "some text";

I use the following code in javascript to replace a table content on a click button, but I want to add another paragraph and between them an image.

function changeContent() {
    var x = document.getElementById('Table').rows;
    var y = x[0].cells;
    y[0].innerHTML = "some text";
Share Improve this question edited Jul 4, 2020 at 18:24 HoRn 1,5185 gold badges20 silver badges28 bronze badges asked Feb 14, 2017 at 19:16 TuduTudu 721 silver badge7 bronze badges 3
  • 2 Is it an exercise? – Ortomala Lokni Commented Feb 14, 2017 at 19:17
  • 1 Show us what you tried already and explain what didn't work about it. – takendarkk Commented Feb 14, 2017 at 19:18
  • Would y[0].innerHTML="<p>some text</p><img src="logo_w3s.gif"><p>some other text</p>" work? – Oren Pinsky Commented Feb 14, 2017 at 19:19
Add a ment  | 

1 Answer 1

Reset to default 4

You can also create the element, then append as a child to a parent.

var p = document.createElement('p');
p.innerHTML = 'some text here';

document.getElementById('some-parent').appendChild(p);
发布评论

评论列表(0)

  1. 暂无评论