I've hit a roadblock while working on my project, specifically with reorganizing my grid using JQuery. To better illustrate the issue, I've simplified it into a fiddle: http://jsfiddle.net/tylerbuchea/QgAqV/
$('div').bind('click', function() {
var pitcher = $('.selected')[0];
var catcher = this;
if (catcher.offsetTop < pitcher.offsetTop || catcher.offsetLeft > pitcher.offsetLeft) {
$(pitcher).before(catcher);
console.log('before');
}
else
if (catcher.offsetTop > pitcher.offsetTop || catcher.offsetLeft < pitcher.offsetLeft) {
$(pitcher).after(catcher);
console.log('after');
}
});
The goal is to move the "selected" div to the clicked div's location, pushing all other divs down or up accordingly. While the current code accomplishes this for single moves, the problem arises when attempting multiple movements. Perhaps the use of .before and .after functions needs reconsideration?