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 "" + $(this).html() + "
";
});
To keep the classes, do:
$('.sideMenu h3').replaceWith(function() {
return $("", {
"class", this.className,
html: $(this).html();
});
});