jQuery: How do I insert an html string an arbitrary number of times (i.e. not with an each() function)?
Posted
by
Sam Bivins
on Stack Overflow
See other posts from Stack Overflow
or by Sam Bivins
Published on 2012-03-19T01:54:25Z
Indexed on
2012/03/19
2:04 UTC
Read the original article
Hit count: 99
jQuery
|jquery-events
I just need to take a certain html query object and append it to an html element a lot of times. I have this:
var box = $("<div class='box'> </div>");
$("#firstbox").after(box);
and it works fine, but it just adds one 'box' after the #firstbox element. I'd like to do something like this:
var box = $("<div class='box'> </div>");
$("#firstbox").after(box * 6000);
so that it will insert 6000 copies of that 'box' html, but this is not working. This is I'm sure the easiest thing to do, but I can't seem to find how to multiply actions like this without using the each() function, which doesn't apply here because I don't have 6000 of anything on my page.
Thanks.
© Stack Overflow or respective owner