Skip to content

Instantly share code, notes, and snippets.

@morningtoast
Created February 13, 2018 20:40
Show Gist options
  • Save morningtoast/9febaf241566818800fafa6115c2210a to your computer and use it in GitHub Desktop.
Save morningtoast/9febaf241566818800fafa6115c2210a to your computer and use it in GitHub Desktop.
Vanilla JS element repeater, useful for flat prototyping
// Add data-repeat attribute to the element you want repeated, the value being the quantity
// That element will be cloned and appended X number of times *after* the original.
var torepeat=document.querySelectorAll("[data-repeat]");
for (a=0;a<torepeat.length;a+=1) {
var el=torepeat[a];
var rpt=el.getAttribute("data-repeat");
for (r=0;r<rpt;r+=1) {
el.insertAdjacentHTML('afterend',el.cloneNode(true).outerHTML);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment