John Edelbi
John Edelbi

Reputation: 1

Replacing tag without losing inner tags in JavaScript

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

Upvotes: 0

Views: 21

Answers (0)

Related Questions