jQuery: Append browser window dimensions to href
<p>I am wanting to use jQuery to add the current browser window dimensions to the end of the <code>href</code> of certain <code>a</code> tags.</p>

<p>The specific <code>a</code> tags all have their <code>href</code> begin with <code>secondary_imgs.php</code> but other than that, differ by containing data, i.e. <code>secondary_imgs.php?Id=x&amp;Title=y</code>. I could easily set all these tags to have a specific class if that helps the problem.</p>

<p>I think the best approach to this would be to append the <code>&amp;width=x&amp;height=y</code> to the end of the <code>href</code> on document ready, and then set a second function to replace those values, whenever the page is resized.</p>

<p>Alas, I am at a loss as to how to complete this. I have the constituent parts (I think), but need help combining them in the proper way.</p>

<p><strong>Here's what I have thus far:</strong></p>

<pre><code>$(document).ready(function () {
    var width = $(window).width();
    var height = $(window).height();
    $("a[href^='secondary_imgs.php']").attr('href', function() {
        return this.append('&amp;w=width&amp;h=height') 
    });
});
</code></pre>

<p>I tried to specify just the <code>a</code> tags who's <code>href</code> <em>begins</em> with <code>secondary_imgs.php</code>. I think that would be the best way of specifying it. But beyond that, I don't know where I'm making a mistake.</p>

<p>For the second half of this, where the values are replaced when the window is resized, I thought using <code>.resize()</code> would be the best to trigger the function, however I don't know how to set it up to <em>replace</em> the values, not add to them.</p>

<p>Any help would be much appreciated. Thank you.</p>
