BroFox86
8/14/2017 - 7:41 PM

[Tag replacement] Replacement an element tag with a new one with preserving attributes #js

[Tag replacement] Replacement an element tag with a new one with preserving attributes #js

$('.selector').replaceWith(function() {
  var replacement = $('<new-tag>').html($(this).html());
  for (var i = 0; i < this.attributes.length; i++) {
      replacement.attr(this.attributes[i].name, this.attributes[i].value);
  } return replacement;
});