Replace attribute in a HTML string in jQuery
<p>I have a string with HTML in it. I want to replace the class attribute with the value in the data-class attribute (if any). This should apply to that particular tag/part of the HTML only.</p>

<p>I have written some of it, but would appreciate a pointer as to finish it:</p>

<pre><code>html = "&lt;div class='hello' data-class='class-name'&gt;Content&lt;/div&gt;&lt;div class='123'&gt;Content&lt;/div&gt;&lt;div data-class="class-111"&gt;&lt;/div&gt;";

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

var final_html = $(html_out).find('[data-class]').attr('class', 'new-value');
</code></pre>

<p>So the above should return:</p>

<pre><code>&lt;div class='class-name' data-class='class-name'&gt;Content&lt;/div&gt;&lt;div class='123'&gt;Content&lt;/div&gt;&lt;div class="class-111" data-class="class-111"&gt;&lt;/div&gt;
</code></pre>

<p>As for if it maintains the data-class part or removes it, that doesn't matter.</p>

<p>The key thing is that the HTML string will contain use of the data-class attribute and I need the class attribute to be overridden with this value.</p>
