How to append array of elements to a Dom

blossom0417
1 min readSep 3, 2019

--

#from array to Dom

var wrapper = document.createElement('div'),
myClass = document.querySelectorAll('.myClass');
myClass[0].parentElement.appendChild(wrapper);
wrapper.id = 'wrapper';
for (var i = 0; i < myClass.length; ++i) {
wrapper.appendChild(myClass[i]);
}

#random Array

# make elements array-like

https://ultimatecourses.com/blog/ditch-the-array-foreach-call-nodelist-hack#problem-10-not-cross-browser

or

shuffle function

function shuffle(array) {  array.sort(() => Math.random() - 0.5);}

#ref

https://gist.github.com/kes3583/f3d513e71928426a1fbc729cf9dc5f58

--

--

No responses yet