create a next cycle
I am trying to create an infinite cycle of elements using the following code:
$('div').click(function(){
move = $(this).detach();
$(this).parent(开发者_如何学编程).append(move);
});
but it just seems to be removing my objects, rather than moving them to the end of the list in order to create the cycle
Where are I going wrong?
move = $(this).detach();
That line removes the element from the DOM. Once you have done this it has no parent. Just remove this line all together.
$(this).parent().append(this);
should be sufficient. It will automatically remove the element and place it where it belongs.
精彩评论