I wonder how to change the HTML tag without replacing the contents. I did something like this:
$('#test > span').replaceWith('<div>' + $('#test > span').html() +'</div>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="test">
<span>hello</span>
<span>hello2</span>
<span>hello3</span>
</div>
Works, but still displays the first value (look code snippet). I think I need to merge .replaceWith() with $(this) but I can't quite do it.