I'm sure this is going to be obvious to the right person, but how can I repeat an element with jQuery? Esentially I want jQuery to repeat an inline element an infinite number of times; like you would use CSS to repeat a graphic for a background texture. I've been researching .clone() and .each() but but could really use some pointers.
Thanks!
http://jsfiddle.net/gRTTJ/
Key line:
$("#repeating").append($(".foobar").clone());
Although if you want it infinitely, it will be an infinite loop (obviously) and not be too useful.
A slightly more reasonable version that runs infinitely:
function repeat()
{
$("#repeating").append($(".foobar:first").clone());
}
$(function () {
setInterval(repeat, 1000);
});
while(true) {
$('#infinity-repeat').append('some text');
}
But that code will crash your browser. Better idea is to do it countable times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With