You need to loop through the attributes of the element:
$('span[data-type="yesno"]').replaceWith(function(){ $li = $("<li>", {html: $(this).html()}); $.each(this.attributes, function(i, attribute){ $li.attr(attribute.name, attribute.value); }); return $li; })
source share