Q:

Increasement number not rising in for loop

I am trying to figure this out. I have 3 buttons id (test1, test2, test3) in my HTML! In my jQuery I have an click function in a for loop like this:
$(document).ready(function() {
    for (var i = 0; i < 3; i++) {
        $("#test"+i).on('click', function() {
            alert("I am clicked! ("+i+")");
        });
    }  
});

Now, I am alerting a message for each of them, nut all the (i) in the alert is giving the last number "3"... How do i get it to write "I am clicked (1)" if I press test1 and equally if I press test2 and test3?
I have a jsfiddle to explain here.
Hoping for help and thanks in advance ;-)

A:

Try something like this 
$(document).ready(function() {
for (var i = 0; i < 3; i++) {
    $("#test"+i).on('click', function() {
       var value = $(this).attr('id');
           value=value.replace("test", "");
           value=parseInt(value)+1;
        alert("I am clicked! ("+value+")");
    });
}  
});

