How do I copy the attributes of one element to another element?
HTML
Javascript solution
Copy the attributes of old element to the new element
const $oldElem = document.querySelector('.old')
const $newElem = document.createElement('div')
Array.from($oldElem.attributes).map(a => {
$newElem.setAttribute(a.name, a.value)
})
Replace the old element with the new element, if required
$oldElem.parentNode.replaceChild($newElem, $oldElem)