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

Filed under:
|

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'>&nbsp</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'>&nbsp</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

Related posts about jQuery

Related posts about jquery-events