I am trying to insert div containers with class names in a box with other containers, specifying a class with numbers.
I can get the following to work correctly while the markup is already in chronological order:
http://play.meyouand.us/140418-rearrange/rearrange4a.html
However, if the markup order is in mixed or reverse chronological order, the function does not put the div containers in the exact position (since the function that I use is before ()):
http://play.meyouand.us/140418-rearrange/rearrange4b.html
Currently, I am fixated on how to solve this, because I'm not sure whether to use the pre-sorting strategy of the boxes first or if there is an existing jQuery function that can just place the div containers exactly where I need them, which made would be his perfect and easy solution. Any thoughts on strategy or methodology will be helpful!
jQuery is still ... - http://jsfiddle.net/foomarks/qM27z/2/
$('[class*=order-]').each(function() {
var cl = $(this).prop('class').split(/\s+/);
var clNumber = cl.map( function(val){
if (val.indexOf('order-') !== -1) {
return val.replace( /^\D+/g, '')
}
});
console.log("clNumber: " + clNumber[1]);
$(this).insertBefore('.box:nth-child('+ clNumber[1] + ')');
});
source
share