Javascript str.replace with html string
<p>EDIT:</p>

<p>in order to be more exhaustive:</p>

<p>I've a dynamic page generated by an external server-side rendering engine (the ERP solution handle the e-commerce too, bad story...) that add its own part of code, like buttons, input form etc. 
I cannot directly control them but and I need to style them.
So I'm using the string replace function of js because I cannot use php, just html/js. But I don't know js, I'm just learning it, and in this case I haven't had things working because of lack of knowledge about syntax / escaping.</p>

<p>The <code>function</code> is loaded with <code>onload="function ()"</code> in the body.</p>

<p>I've just added a <code>&lt;div id="replace-input"&gt;</code> outside the parts of the code needed to be replaced (in this case is an input form for the qty of items to be sended into the cart)</p>

<p>thanks</p>

<p>END EDIT</p>

<p>I cannot find a working solution to replace an html string like</p>

<pre><code>&lt;input name="qty" id="qty" size="6" maxlength="6" value="1" class="input"&gt;
</code></pre>

<p>into another one like</p>

<pre><code>&lt;div class="product-qty"&gt;
&lt;label for="qty"&gt;Qty:&lt;/label&gt;
&lt;div class="custom-qty"&gt;
&lt;button type="button" class="reduced items" onclick="var result = document.getElementById('qty');   var qty = result.value;  if (!isNaN(qty) &amp;amp;&amp;amp; qty &gt; 1)result.value--; return false;"&gt; &lt;i class="fa fa-minus-square-o"&gt;&lt;/i&gt; &lt;/button&gt; 
&lt;input type="text" name="qty" id="qty" maxlength="12" value="1" title="Qty" class="input-text qty"&gt; 
&lt;button type="button" class="increase items" onclick="var result = document.getElementById('qty');   var qty = result.value;  if (!isNaN(qty)) result.value++;return false;"&gt; &lt;i class="fa fa-plus-square-o"&gt;&lt;/i&gt; &lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>I'm using this function</p>

<pre><code>var str = document.getElementById("replace-input").innerHTML; 
    var res = str.replace(/HereIHaveToAddTheFirstString/g, "HereTheSecondOne");
    document.getElementById("replace-input").innerHTML = res;
</code></pre>

<p>but I don't know how to write the strings in order to be parsed correctly.</p>