I want to replace HTML tag with another JavaScript

117 Views Asked by At

enter image description here

In JavaScript, I would like to simply change the

<section class="row"> to <div class="row">

Preferably in the least amount of code as possible to keep it simple :) I was using document.querySelector but that is as far as I got. Thank you for your help!!

1

There are 1 best solutions below

0
On

You could try

const newDiv = document.createElement('div');
const oldSection = document.querySelector('section.row');
newDiv.innerHTML = oldSection.innerHTML;
newDiv.className = 'row';
oldSection.replaceWith(newDiv);