1. robots
  2. wrong
  3. hi
  4. bye
i want to replace ol b" />
  1. robots
  2. wrong
  3. hi
  4. bye
i want to replace ol b" />
  1. robots
  2. wrong
  3. hi
  4. bye
i want to replace ol b"/>

Replacing tag without losing inner tags in JavaScript

19 Views Asked by At

Let suppose I have this HTML code :

<div id="actual">
        <ol>
          <li>robots</li>
          <li>wrong</li>
          <li>hi</li>
          <li>bye</li>
        </ol>
      </div>

i want to replace ol by ul without losing the inner tags (li)and thier content

i tried that:

        const actual = document.getElementById('actual');
        const ulReplace = document.createElement('ul');
        actual.children[0].replaceWith(ulReplace);

but i replace the ol by ul and remove every thing inside it.

also i try to clone the content and re-append it after but also i lose it when removed

0

There are 0 best solutions below