0

I have a span in the form of:

<span eid="4" etype="dc" class="remove-absolute" style="display: block">
  <div>
    <span>ttttttt</span>
    <p>ttttttt</p>
  </div>
</span>

I want to change the outerHTML(from span to div), so it looks like:

<**div** eid="4" etype="dc" class="remove-absolute" style="display: block">
  <div>
    <span>ttttttt</span>
    <p>ttttttt</p>
  </div>
</**div**>

I checked other solutions, I tried replaceWith, but it doesn't work.

I tried:

$('[etype="dc"]')[0].replaceWith("abcd");  


$('[etype="dc"]')[0].outerHTML => is still unchanged. canI get some help?

Thanks!

kevinzf
  • 163
  • 12
  • 1
    Does this answer your question? [Change tag using javascript](https://stackoverflow.com/questions/13389751/change-tag-using-javascript) – Varad Mondkar Feb 11 '20 at 19:20
  • Not fully.. I tried $(this).replaceWith($('
    ' + this.innerHTML + '
    ')), but it doesn't keep the attribute of the tag. I want to keep eid="4" etype="dc" class="remove-absolute" style="display: block"... Thanks! @VaradMondkar
    – kevinzf Feb 11 '20 at 19:25

0 Answers0