How to change element tag without losing attributes

This question already has an answer here:

I want to change an element tag but without losing the element's attributes.

This is the element:

<h4 class="form-title ng-binding" id="s50" ng-bind-html="'s50' | translate" translate-cloak="s50">searching</h4>

I want to change h4 to h1 so it will look like this:

<h1 class="form-title ng-binding" id="s50" ng-bind-html="'s50' | translate" translate-cloak="s50">searching</h1>

I've tried the code:

$('h4').replaceWith($('<h1>' + this.innerHTML + '</h1'));

but in this way I'm losing the attributes this.innerHTML returns undefined I've tried to change this.inner.HTML to $('h4').innerHTML and still it returns undefined.

Answers 1

Related Articles