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
1 Answer
Reset to default 4You 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);