This should replace all classes with the corresponding data-change attribute.
So if I had:
<div class="hello" data-change="new-class">
...I would expect it to return
<div class="new-class" data-change="new-class">
My code changes one of them (the one on the button) but not the other.
What am I doing wrong?
Thanks for any help.
--
Apparently I need to post the JS Fiddle code too:
var str = '<div class="original-class" data-change="new-class">Hello</div><div class="class-123"><input type="button" class="start-class" data-change="any-new-class" value="Click Me"></div>';
var html = $('<div/>').html(str).contents();
$('[data-change]', html).attr('class', function() { return $(this).data('change') });
alert( $(html).parent().html() );