Why is 'createElement' adding extra tags?

23 Views Asked by At

If I add a row to a table with an existing th row

y=document.createElement('tr');
z=document.createElement('td');
z.append(document.createTextNode('abc'));
y.append(z);
x.append(y);
console.log(x.innerHTML);
<table id="x">
<tr><th>xyz</th></tr>
</table>

I get

<tbody><tr><th>xyz</th></tr></tbody><tr><td>abc</td></tr>

from innerHTML, but this has added a tbody tag.

I wanted

<tr><th>xyz</th></tr><tr><td>abc</td></tr>
0

There are 0 best solutions below