I’m not using jQuery.
I want to remove all table tags (table,td,tr,etc.) and their respective closing tags, while keeping the content. I can’t edit the code that creates this HTML. It generates something like this:
<table>
<tbody>
<tr>
<td>
<div>
<a></a>
</div>
</td>
</tr>
</tbody>
</table>
I want to remove all the junk so it just ends up like this:
<div>
<a></a>
</div>
I’ve searched for a while and I can’t find anything like it.
Assuming you are working on the DOM (client side) and have a reference to the table:
DEMO
This iterates over all cells and appends each child node to a
DocumentFragment[MDN]. By doing this, the child node (the content we want to keep) is removed from the table. Then all of them are inserted before the table and the table is removed.If you have the HTML as string, you can generate the DOM by creating a dummy element:
If this is not what you want, you have to provide more information.