Wrapping a HTML tag that currently is in a string? : <p>I have HTML as a string, something like:</p>

<pre><code>&lt;p&gt;some text&lt;/p&gt;&lt;p&gt;some more text&lt;/p&gt;&lt;table&gt;&lt;th&gt;....&lt;/table&gt;
</code></pre>

<p>I wish to wrap table in a div tag - table could be anywhere.</p>

<p>I've thought about using <code>replace</code> but I would have to replace both the opening table tag and the closing table tag.</p>

<p>Is there a way to just wrap the table element?</p>

<p>Vanilla JS only.</p>
