This loop doesn't seem to be working, I'm not sure where i'm going wrong but would appreciate any help.
var j = 0;
for (j = 0; j < 10; j++) {
$('#btn-' + j).click(function() {
alert(j);
});
}
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<button id='btn-0'>One</button>
<button id='btn-1'>Two</button>
<button id='btn-2'>Three</button>
<button id='btn-3'>Four</button>
Basically on the click of the button it should alert out the number the loop is up to (right?) but it just alerts '10' on every one?
It's late and I know I must be doing something wrong, but I can't think what.
Here is a fiddle of my loop: https://jsfiddle.net/p8v5sejr/