This is a example of having <p> tags with numeric id attributes. For example "<p id="1">", "<p id="2">". I ran into a situation where there ids were goin from 9-1, and i need them to go 1-9, so i found this little piece to sort the "<p>" by their id attribute. In this example "clientImages" is a wrapper div for the images and the "<p>'s".
//create div placeholders for content.
var clientImages = customersContainer.find('img').parents('p');
//the image <p> are in opposite order we need to reorder them to 1-9 to match description <p>'s'
clientImages.sort(function(a,b){
var compA = $(a).attr('id');
var compB = $(b).attr('id');
return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
})