Given: a container with three elements. Task: take the first element and move it to the end of the container (it will be 2, 3, 1 sequence), then do the same for the first element (3, 1, 2 will result).
In the solution below, the first time everything works successfully:
$container.append($allElements.first()); If you duplicate this line and execute the code, then moving to the sequence (3, 1, 2) will not occur. Perhaps I misunderstood the previously studied, but it seems like the jQuery object changes its state when some changes occur with the corresponding DOM elements.
Trying to fetch again instead of the existing $container object:
$('.container').append($allElements.first()); Nothing happens either. Explain, please, the reasons for this.
PS It is possible to solve the problem posed through convoluted conditions and arithmetic operations, but striving for simplicity of the code, I would like to work only in the first element of $allElements.first() (in each iteration).
let $container = $('.container'); let $allElements = $('.element'); $container.append($allElements.first()); //$container.append($allElements.first()); // не работает //$('.container').append($allElements.first()); // так тоже .container { display: inline-block; background: rgba(255, 0, 0, 0.25); line-height: 1; } .element { display: inline-block; width: 100px; height: 100px; } .element-first { background: rgba(255, 255, 0, 0.25); } .element-second { background: rgba(0, 128, 0, 0.25); } .element-third { background: rgba(0, 0, 255, 0.25); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div class="element element-first">1</div> <div class="element element-second">2</div> <div class="element element-third">3</div> </div> 
jQueryUI-draggableLensky,jQueryUI-draggablemakes it possible to drag items with the mouse cursor. Maybe it would be useful to me if I did not make a slider. So in my case, we need full automation. - Bokov Gleb