Created
January 17, 2014 01:26
-
-
Save zackmdavis/8466875 to your computer and use it in GitHub Desktop.
apparently I don't understand scope in JavaScript
This file contains hidden or 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
$(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