My current task involves an HTML table.
I am looking to remove all HTML attributes from the table so that it resembles the structure below:
<table>
<thead>
<tr>
<th>...</th>
...
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
...
</tr>
</tbody>
</table>
How can I achieve this using plain JavaScript?
I have been through various discussions on similar topics, but they often rely on jQuery (which I cannot use) or do not provide the desired outcome for me.
<table class="wikitable sortable jquery-tablesorter" style="margin-left:auto;margin-right:auto;text-align: right">
<thead>
<tr>
<th data-sort-type="number" class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Rank
</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Country/Territory
</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Int$
</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td align="left"><span class="flagicon"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Flag_of_Qatar.svg/23px-Flag_of_Qatar.svg.png" decoding="async" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Flag_of_Qatar.svg/35px-Flag_of_Qatar.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/6/65/Flag_of_Qatar.svg/46px-Flag_of_Qatar.svg.png 2x" data-file-width="1400" data-file-height="550" width="23" height="9"> </span>
<a
href="/wiki/Qatar" title="Qatar">Qatar</a>
</td>
<td>128,378
</td>
</tr>
<tr>
<td>—</td>
<td align="left"><i><span class="flagicon"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/6/63/Flag_of_Macau.svg/23px-Flag_of_Macau.svg.png" decoding="async" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/6/63/Flag_of_Macau.svg/35px-Flag_of_Macau.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/6/63/Flag_of_Macau.svg/45px-Flag_of_Macau.svg.png 2x" data-file-width="450" data-file-height="300" width="23" height="15"> </span><a href="/wiki/Macau" title="Macau">Macau</a></i></td>
<td>115,123
</td>
</tr>
<tr>
<td>2</td>
<td align="left"><span class="flagicon"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/da/Flag_of_Luxembourg.svg/23px-Flag_of_Luxembourg.svg.png" decoding="async" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/da/Flag_of_Luxembourg.svg/35px-Flag_of_Luxembourg.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/da/Flag_of_Luxembourg.svg/46px-Flag_of_Luxembourg.svg.png 2x" data-file-width="1000" data-file-height="600" width="23" height="14"> </span>
<a
href="/wiki/Luxembourg" title="Luxembourg">Luxembourg</a>
</td>
<td>103,662
</td>
</tr>
<!-- More rows follow -->
</tbody>
<tfoot></tfoot>
</table>