For your convenience, here's an interactive jsfiddle version of my code. Here's the offending code:
for i in [1, 2, 3, 4, 5, 6, 7, 8]
console.log "cell #{i} was created!"
cell = $('<div class="inventory-cell"></div>').mousedown (event) ->
alert "#{i} was clicked!"
$("#inventory-grid").append(cell)
And here's the html:
<div id="inventory-dialog" class="dialog">
<div id="inventory-grid"></div>
</div>
Here's how it's supposed to work. This will generate a bunch of cells in a loop. If I click on the first one I want it to alert, "1 was clicked!" and when I click on the last, I want it to say, "8 was clicked!" But for some reason, every one I click on says, "8 was clicked". Why is this happening?