Change Tag Name in jQuery

Something Like that:
span to a

Change Tag Name

For that you need to create first html code.

HTML

<span class="fusion-imageframe imageframe-none imageframe-5 hover-type-none fancybox" id="gallery-0"><img src="http://www.olizki.com/wp-content/uploads/2016/09/6C041B61-e1513840805408.jpg"></span>

Use jQuery Library.

After that add this JQuery code.

JS

(function($){
  $('span.fancybox').each(function(){
    $(this).replaceWith(function() {
      return $('', {
        class: this.classList.value,
        rel: this.attributes.id.value,
        href: this.children[0].attributes.src.value,
        html: this.innerHTML
      })        
      });
  });
})(jQuery)

rel:
rel there I am adding attribute but get ID value of span

href:
href adding attribute but href taking src of child element IMG

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”opLKxo” default_tab=”js,result” user=”pradeepanvi”]See the Pen Change Tag Name in jQuery by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Leave a Reply

Your email address will not be published. Required fields are marked *