picture

Move the last child to the first position

My HTML:

<div id="my-slider"> <img src="/slider/pic/bf3.jpg" alt="picture"> <img src="/slider/pic/bf3_cq.jpg" alt="picture"> <!-- etc --> </div> 

In the specific case, I want to move the last img tag to the first position (according to the parent)

I'm trying to:

  curr.css('left', 0); curr.prepend(curr.parent()); 

I can change the css, but the error is raising the second line:

HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy

Can anyone give me any advice?

+6
source share
3 answers
 curr.parent().prepend(curr); 

or

 curr.prependTo(curr.parent()); 
+17
source

You can use prepend() :

 $('#my-slider').prepend($('#my-slider img:last')) 

http://jsfiddle.net/Uttv8/

+5
source

try http://jsfiddle.net/uttara/TFYXA/

 $("#my-slider img:last-child").prependTo("#my-slider") 
+3
source

Source: https://habr.com/ru/post/921565/


All Articles