JSFiddle - React, Tailwind, and code Playground

by shubanker Chourasia

HTML

<p class='renameMe'>Hello!</p>
<a id="change">change</a>

JavaScript

$(function(){
  function renameElement($element,newElement){

      $element.wrap("<"+newElement+">");
      $newElement = $element.parent();

    //Copying Attributes
    $.each($element.prop('attributes'), function() {
      $newElement.attr(this.name,this.value);
      });

      $element.contents().unwrap();

      return $newElement;
  }
  
  $('a#change').click(function(){
  	renameElement($('p.renameMe'),'h5');
  });
});