Reputation: 7734
i'v clone some elements list, but i need to clone it more than one time, can you tell me how to do it?
$('.main_content ul li').clone().prependTo('.main_content ul')
Much thx for help.
Upvotes: 1
Views: 3716
Reputation: 9
Or instead of using .prependTo() replace that with .insertAfter()
for example:
jQuery
$(function() {
for () {
$('.main_content ul li').clone().insertAfter('.main_content ul li');
}
});
Upvotes: 0
Reputation: 431
I'm not entirely sure what you are asking, you want to clone listed tags into it's same parent? This will result in the same listed items being in the same parent.
Or do you want to clone the parent? Or do you want to clone only certain listed items?
Is this what you are looking for?
<div class="main_content">
<ul>
<li>1</li>
<li>2</li>
</ul>
</div>
<script type="text/javascript">
$(document).ready(function(){
var numberOfCopies = 5;
for(x = 0; x < numberOfCopies; x++){
$(".main_content ul li").each(function(){
$(this).clone().appendTo(".main_content ul");
});
}
})
</script>
Upvotes: 0
Reputation: 1942
Try this maybe?
var objToClone = $('.main_content ul li');
for (var i = 0; i < 10; i++)
objToClone.clone().prependTo('.main_content ul');
Upvotes: 2