8

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?

keram
  • 2,181
  • 4
  • 23
  • 29

3 Answers3

24
curr.parent().prepend(curr);

or

curr.prependTo(curr.parent()); 
adeneo
  • 303,455
  • 27
  • 380
  • 377
6

You can use prepend():

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

http://jsfiddle.net/Uttv8/

Ram
  • 140,563
  • 16
  • 160
  • 190
6

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

$("#my-slider img:last-child").prependTo("#my-slider")
Uttara
  • 2,466
  • 2
  • 23
  • 35