Skip to content

Instantly share code, notes, and snippets.

@danielsmith-eu
Created March 21, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsmith-eu/49dd6715357a23983ae30af3e2d44aa4 to your computer and use it in GitHub Desktop.
Save danielsmith-eu/49dd6715357a23983ae30af3e2d44aa4 to your computer and use it in GitHub Desktop.
Sort BA cheap flights page with JS
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