Created
March 21, 2017 20:18
-
-
Save danielsmith-eu/49dd6715357a23983ae30af3e2d44aa4 to your computer and use it in GitHub Desktop.
Sort BA cheap flights page with JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortTable(){ | |
var tbl = $("#tabpanel01"); | |
var store = []; | |
var rows = tbl.find("tr"); | |
for(var i=0; i<rows.length; i++){ | |
var row = rows[i]; | |
console.debug($(row)[0]); | |
try { | |
var sortnr = parseFloat($(row).find(".price")[0].innerText.substr(1)); | |
if(!isNaN(sortnr)) store.push([sortnr, row]); | |
} catch(e) { | |
console.log("end"); | |
} | |
} | |
store.sort(function(x,y){ | |
return x[0] - y[0]; | |
}); | |
for(var i=0; i<store.length; i++){ | |
tbl.find("tbody")[0].appendChild(store[i][1]); | |
} | |
store = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment