I'm trying to store multiple DOM elements into an array, and then later use the array to put specific elements into the HTML Document. However, I haven't found a way that works... I've tried .innerHTML to store in the array and insertAdjacentHTML instead of appendChild but it doesn't work.
This is what I'm trying to do, but it doesn't work. Any other solutions/methods to achieve this?
const arr = [];
const test = document.querySelector('.one');
arr[0] = test;
document.querySelector('.three').appendChild(arr[0])
/* Styles for visual feedback only */
div[class] {
border: 1px solid #999;
position: relative;
padding: 1rem .2rem .2rem;
}
div[class]:before {
content: attr(class);
position: absolute;
top: .1rem;
font-size: .8rem;
color: #999;
}
<div class="one">
<div class="two">
<p> Test </p>
</div>
</div>
<div class="three">
</div>