0
In an HTML form I created a field input[type='text']
with the attribute name='input[][nome]'
and this field is created in the DOM dynamically on demand of the user, if the user create 3 new inputs
the return of the attribute name
in the console.log
would be:
input[0][name]
input[1][name]
input[2][name]
I’m using Jquery
to facilitate development time and a good part is in Javascript
, I made a debugger that displays in console.log
which input is receiving the focus and with the code below returns me the attribute name
.
<input type='text' name='input[][nome]' class='add-item'/>
<script>
$('.add-item).on('click',function(){
var nomeInput = $(this).attr('name');
console.log(nomeInput); // retorna input[0][nome]
})
</script>
Inside the javascript code I would like to check what is the value of the current key, in the above case it is 0, but it is possible to identify this without structural change of this function, just incrementing the same?
solved general, I had mapped everything to get the index, unknown . index(), today tested . map() and returned different, should report the divergence of the snippet to the OS. Thank you cordial.
– ElvisP