As mentioned in another answer, you can access the current item in the callback using $(this) .
However, I would not rely on regex to extract an integer value.
Each function receives two parameters, the first is an index, the second is an element (equivalent to this ).
If the values ββare sequential and start at 0, you can simply use the 1st parameter for each callback:
<input type='text' name='value[0]' class='kp'> <input type='text' name='value[1]' class='kp'> $( ".kp" ).keyup(function() { $('input[name^="value"]').each(function(index, element) { console.log(index); }); });
If not, I would suggest adding the data attribute in html to contain the index:
<input type='text' name='value[13]' data-index='13' class='kp'> <input type='text' name='value[106]' data-index='106' class='kp'> $( ".kp" ).keyup(function() { $('input[name^="value"]').each(function(index, element) { console.log($(element).data('index')); }); });
Steve source share