String to jQuery object, replace attribute and then back to string again (see JS Fiddle)
<p><a href="http://jsfiddle.net/r4KL9/" rel="nofollow">http://jsfiddle.net/r4KL9/</a></p>

<p>This should replace all classes with the corresponding data-change attribute.</p>

<p>So if I had:</p>

<pre><code>&lt;div class="hello" data-change="new-class"&gt;
</code></pre>

<p>...I would expect it to return</p>

<pre><code>&lt;div class="new-class" data-change="new-class"&gt;
</code></pre>

<p>My code changes one of them (the one on the button) but not the other.</p>

<p>What am I doing wrong?</p>

<p>Thanks for any help.</p>

<p>--</p>

<p>Apparently I need to post the JS Fiddle code too:</p>

<pre><code>var str = '&lt;div class="original-class" data-change="new-class"&gt;Hello&lt;/div&gt;&lt;div class="class-123"&gt;&lt;input type="button" class="start-class" data-change="any-new-class" value="Click Me"&gt;&lt;/div&gt;';

var html = $('&lt;div/&gt;').html(str).contents();

$('[data-change]', html).attr('class', function() { return $(this).data('change') });

alert( $(html).parent().html() );
</code></pre>
