I’m trying to create a function that would copy the <p>
text and paste it within the same div (duplication) on click.
I’ve tried a couple of methods, none of them worked, unfortunately.
function duplicate() {
let clone = document.querySelector('.header p').cloneNode(true);
document.querySelector('.header').appendChild(clone);
}
<div class='header'>
<p onclick="duplicate();">Text</p>
</div>