Update: I was able to find a solution... The sort code below actually works.
I'm using jQuery (ajax) to parse and XML file, adding the data to an array, sorting it, and then displaying it. Everything works great in Firefox, but it behaves erratically in Chrome (i.e. It only partially sorts)
Here is the page: http://teachwritework.com/part-time-teaching-jobs.php
I've been at this for over 3 hours and I'm stuck. If anyone can point out the error in my ways, I would greatly appreciate it. I'm a rookie with JS / Ajax, so be gentle. My code is as follows:
$(document).ready(function () {
var dates = [];
$.ajax({
type: "GET",
url: "jobs-for-teachers.xml",
dataType: "xml",
success: xmlParser
});
}); /* End get-xml */
function xmlParser(xml) {
var dates = [];
$(xml).find("job").each(function () {
dates.push({
jobtitle: $(this).find("title").text(),
jobsource: $(this).find("source").text(),
posted: $(this).find("posted").text(),
locale: $(this).find("location").text(),
employer: $(this).find("employer").text(),
comp: $(this).find("comp").text(),
schedule: $(this).find("schedule").text(),
reqs: $(this).find("reqs").text(),
desc: $(this).find("desc").text(),
contact: $(this).find("contact").text()
});
}); /* End parsing xml */
/* Updated code to sort in reverse chronological order */
dates.sort(function(a,b){
if(a.posted<b.posted) return 1;
if(a.posted>b.posted) return -1;
return 0;
});
var html=[];
$.each(dates, function() {
html.push(
'<h2>' + this.jobtitle
+ '</h2><br><h5>Posted: </h5>' + this.posted
+ '<br><br><h5>Location: </h5><div class="tfield">' + this.locale
+ '<br></div><h5>Employer: </h5><div class="tfield">' + this.employer
+ '<br></div><h5>Compensation: </h5><div class="tfield">' + this.comp
+ '<br></div><h5>Schedule: </h5><div class="tfield">' + this.schedule
+ '<br></div><h5>Description: </h5><div class="tfield">' + this.desc
+ '<br><br></div><h5>Requirements: </h5><div class="tfield">' + this.reqs
+ '<br></div><h5>Contact: </h5><div class="tfield">' + this.contact
+ '<br><br></div><h5>Source: </h5><div class="tfield">' + this.jobsource
+ '</div><br class="clr"><br><br><hr><br><br>'
);
});
$('.listings').append(html.join(''));
} /* End xml-parser */