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,321
  • 4
  • 24
  • 29

3 Answers3

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

or

curr.prependTo(curr.parent()); 
adeneo
  • 312,895
  • 29
  • 395
  • 388
6

You can use prepend():

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

http://jsfiddle.net/Uttv8/

Ram
  • 143,282
  • 16
  • 168
  • 197
6

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

$("#my-slider img:last-child").prependTo("#my-slider")
Uttara
  • 2,496
  • 3
  • 24
  • 35