Search code examples
typeshtmlelements

Change the type of an html-element with jQuery


I want to change an h4-element to an h3-element.

Is there any easy possibility with jQuery?

Of course there is the .replaceWith-function. But the content of my h3-elemtent must not be deleted.

Thanks!


Solution

  • This should work

    $("h4").each(function () {
        var self = $(this);
        self.replaceWith("<h3>"+self.html() + "</h3>");
    });