jquery move element to last child position

There is no need to call $ more than once, just move the element to the end of its parent:

var myEl = $('.my-el-selector');
myEl.appendTo(myEl.parent());

Try

var mydiv = $('my-div-selector');
mydiv.find('.myUniqueElement').appendTo(mydiv)

or simple

$('my-div').append($('.myUniqueElement'))

This is my solution and I think this is the best way I can use .insertAfter():

HTML:

<div class='p'>
    <div class='myUniqueElement'>unique</div>
    <div>item</div>
    <div>item</div>
    <div>item</div>
</div>
<input type='button' id='b' value='Do'/>

jquery:

$('#b').on('click',function(){
    $('.myUniqueElement').insertAfter($('.p :last-child'))
});

The point is :last-child and this is the fiddle: http://jsfiddle.net/silverlight/RmB5K/3/


There is no need to use .insertAfter. You should also not use .clone as it'll remove any attached data or events, unless you use .clone(true).

Simply use .appendTo to add the target element to the div and it'll get detached from its original position and added as the last child of the div:

$('.myUniqueElement').appendTo('#my-div');

Tags:

Html

Dom

Jquery