Created
February 13, 2018 20:40
-
-
Save morningtoast/9febaf241566818800fafa6115c2210a to your computer and use it in GitHub Desktop.
Vanilla JS element repeater, useful for flat prototyping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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