title: How can we append html within html string using javascript/typescript?
body: <p>I have an HTML string like this:</p>
  <pre><code>    &quot;Some text &lt;span&gt;something&lt;/span&gt; some more text &lt;span&gt;something inside second span&lt;/span&gt;...&lt;span&gt;nth span&lt;/span&gt;&quot;
  </code></pre>
  <p>I want to create a function that injects some HTML within each span, before each span tag close. Let's take the anchor tag so that the final HTML string becomes like this:</p>
  <pre><code>    &quot;Some text &lt;span&gt;something&lt;a&gt;anchor&lt;/a&gt;&lt;/span&gt; some more text &lt;span&gt;something inside second span&lt;a&gt;anchor&lt;/a&gt;&lt;/span&gt;...&lt;span&gt;nth span&lt;a&gt;anchor&lt;/a&gt;&lt;/span&gt;&quot;
  </code></pre>
  <p>Please somebody tell me how I can achieve that? Please note that the injected dom will be the same throughout.</p>
  <p>I have tried:</p>
  <pre><code>    content.replace(&quot;&lt;/span&gt;&quot;,&quot;&lt;a&gt;anchor&lt;/a&gt;&lt;/span&gt;&quot;);
  </code></pre>
  <p>But it only replaced first closing span tag from that html content string.</p>