Copying a large number of DOM elements The aim is to duplicate and append each .grid__item into the .gallery element. The following code was my first instinct, and works fine, but can't help wonder if there is a more efficient way to write this. My concern is when the element count gets up to a high amount, that there will be some delay.

Generate Dummy Elements (PHP)

&lt;section class="grid"&gt;
    &lt;?php for ($i = 0; $i &lt; 100; $i++) :
        $randH = rand(500, 1010);
        $randW = rand(500, 1010);
        $imgUrl = 'http://placehold.it/' . $randH . 'x' . $randW;
    ?&gt;
        &lt;article class="grid__item"&gt;
            &lt;img src="&lt;?php echo $imgUrl; ?&gt;"&gt;
            &lt;p&gt;&lt;?php echo $imgUrl; ?&gt;&lt;/p&gt;
        &lt;/article&gt;
    &lt;?php endfor;?&gt;
&lt;/section&gt;

&lt;section class="gallery"&gt;
&lt;/section&gt;


Copy Elements (JS)

let $gridItems = document.querySelectorAll('.grid__item'),
    $gallery = document.querySelector('.gallery');

let timeBefore = new Date().getTime();

for (let i = 0; i &lt; $gridItems.length; i++) {
    $gallery.innerHTML += '&lt;article class="gallery__item"&gt;' + $gridItems[i].innerHTML + '&lt;/article&gt;';
}

let timeAfter = new Date().getTime();

console.log(timeAfter - timeBefore)
As a followup to your "selfie" answer :D

new Date().getTime()

// to

Date.now()


The effect is the same, but the difference is that you avoid generating a new Date object for the operation. Date.now() just returns the current timestamp.

$galleryItem.innerHTML = $gridItems[i].innerHTML


One problem with innerHTML is that it carries the state of whatever it was you fetched it from. This means if something happens to add the attribute data-foo="bar" into the element or its descendants, this gets copied over. You don't know what data-foo="bar" entails, and there might be side-effects.

An actual case is jQuery using an internal cache mapping of element references. It uses key of that mapping as a custom attribute on the element referenced. Using innerHTML would carry over this attribute to the new stuff, when it should not.