Skip to content

Instantly share code, notes, and snippets.

@zackmdavis
Created January 17, 2014 01:26
Show Gist options
  • Save zackmdavis/8466875 to your computer and use it in GitHub Desktop.
Save zackmdavis/8466875 to your computer and use it in GitHub Desktop.
apparently I don't understand scope in JavaScript
$(document).ready(function() {
var job_postings_data = JSON.parse($("#job_postings_data").html());
for (var job in job_postings_data) {
var job_item_selector = "#" + job + "-item";
$(job_item_selector).on("click", function(e) {
var this_job = job;
e.preventDefault();
$(".job-post-item").removeClass("selected");
$(this).addClass("selected");
console.log(this_job); // always prints the last job in job_postings_data (!?)
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment