How to append to an anchor's href attribute with JavaScript but not affect query string?
<p>I have some links (they are in an array, not <code>a</code> elements)...</p>

<ul>
<li><code>http://example.com</code></li>
<li><code>http://example.com?bob=true</code></li>
<li><code>http://example.com?sandy=true&amp;bob=false</code></li>
</ul>

<p>I want to append something after the <code>.com</code> but before the start of the query string.</p>

<h3>Example</h3>

<ul>
<li><code>http://example.com/search/results</code></li>
<li><code>http://example.com/search/results?bob=true</code></li>
<li><code>http://example.com/search/results?sandy=true&amp;bob=false</code></li>
</ul>

<p>What is the best way?</p>

<h3>Update</h3>

<p>I answered my own question, however if my solution can be improved (or you can see some problem with it) please do post your own answer.</p>
