I am finding child elements from the parent element and sorting them and then adding them on the parent element again:
$('#parentElement').find('.childElement').sort(function(a, b) {
var contentA = parseInt($(a).attr('data-name'));
var contentB = parseInt($(b).attr('data-name'));
return (contentA < contentB) ? 1 : (contentA > contentB) ? -1 : 0;
}).appendTo('#parentElement');
But I want to append only the first 5 sorted child elements on the parent element. I don't want to append all child elements. Any solution?