I\'ve this markup:
#a(data-row=\"2\", data-col=\"3\") a
#b(data-row=\"1\", data-col=\"1\") b
#c(data-row=\"1\", data-col=\"3\") c
#d(data-row=\"2\", data-col
The second value is only applicible if the first values are equal, so this should do it for you:
var gridElements = $('div');
gridElements.sort(function (a, b) {
var contentA =parseInt( $(a).attr('data-row'));
var contentB =parseInt( $(b).attr('data-row'));
//check if the rows are equal
if (contentA === contentB) {
var colA = parseInt( $(a).attr('data-col'));
var colB = parseInt( $(b).attr('data-col'));
//do the same as your already doing but using different data, from above
return (colA < colB) ? -1 : (colA > colB) ? 1 : 0;
}
else {
return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
}
});