Replacing an Element in jQuery <p>I'm trying to modify an element in jQuery programmatically, i.e. a number in <em>docID</em> increments up to a maximum number. I'm replacing text on a series of images on a page from <em>Download</em> to <em>View</em>. If I use <code>#ctl00_cphMainContent_dlProductList_ct100_ctl00_lnkProofDownload</code> instead of <code>docID</code> in the <code>$(docID).text(...)</code> part of the code, the text gets replaced correctly. When I use the <code>docID</code> variable in its place, it doesn't work.</p> <p>What am I doing wrong here?</p> <p>Thanks.</p> <pre><code>var max = 10; var count = 100; var s1 = "#ctl00_cphMainContent_dlProductList_ct"; var s2 = "_ctl00_lnkProofDownload"; var docID = ""; for (i = 1; i &lt;= max; i++) { docID = s1.concat (count++, s2); $(document).ready(function() { $(docID).text(function(i, oldText) { return oldText === 'Download' ? 'View' : oldText; }); }); } </code></pre> <p>This is the HTML code that is being modified. The word Download is replaced by View.</p> <pre><code>&lt;a id="ctl00_cphMainContent_dlProductList_ctl00_ctl00_lnkProofDownload" href="../../../Controls/StaticDocProof.ashx?qs=op/5WlcUxeg849UT973Mwf0ZnNcMLfe3JYAe7EnJORsdyETYV1vcKaj0ROc2VrN5fXfYjO2MM6BUYXzX2UKmog==" &gt;Download&lt;/a&gt; </code></pre>