jQuery: How to remove this code redundancy?
<pre><code>    clone.find('[id]').each(function() {
        id = $(this).attr('id');
        ind = id.search(/\d+$/);
        $(this).attr('id', id.substr(0,ind)+id_counter);
    });
    clone.find('[for]').each(function() {
        id = $(this).attr('for');
        ind = id.search(/\d+$/);
        $(this).attr('for', id.substr(0,ind)+id_counter);
    });
</code></pre>

<p>I know I can find elements that have either the <code>id</code> attribute <em>or</em> the <code>for</code> attribute, but then how do I know which one I need to set?</p>
