Use .html()
to keep all the HTML structure. text()
just gets the plain text, and throws away all the tags.
$('.sideMenu h3').replaceWith(function () {
return "<h2>" + $(this).html() + "</h2>";
});
To keep the classes, do:
$('.sideMenu h3').replaceWith(function() {
return $("<h2>", {
"class", this.className,
html: $(this).html();
});
});