How do I replace a heading tag with a link inside while preserving the link?

Solution:

Try out

  $(".blog-sidebar h3.entry-title").replaceWith(function () {
         return "<span class='sidebar-post-title'>" + $(this).html() + "</span>";
    });