Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move last child to first position

Tags:

jquery

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>

On specific event I want to move last img tag to first position (according to parent)

I try:

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

I can change css, but second line raising error:

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

Could someone give me any advice?

like image 238
keram Avatar asked Jul 28 '12 12:07

keram


3 Answers

curr.parent().prepend(curr);

or

curr.prependTo(curr.parent()); 
like image 116
adeneo Avatar answered Nov 30 '22 13:11

adeneo


You can use prepend():

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

http://jsfiddle.net/Uttv8/

like image 33
undefined Avatar answered Nov 30 '22 13:11

undefined


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

$("#my-slider img:last-child").prependTo("#my-slider")
like image 32
Uttara Avatar answered Nov 30 '22 12:11

Uttara