/ Published in: JavaScript
when need to created a dom element repeatedly , use string concatenation to avoid for loop you can use repeat function from below.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function repeat(str,n) { return new Array(n+1).join(str); } repeat("<li class='empty'>" , 2); //output: "<li class='empty'><li class='empty'>"