I have a tree with checkboxes and their id has key for item and value as their value.
<input type="checkbox" name="list_code[4]" id="list_code[4]" value="AG12345678" checked="checked">
When users select a tree element I can access those by
$('input[name^="list_code"]').each(function() {
if ($(this).attr('checked'))
list_code = $(this).val();
});
I am able to get value AG12345678 but I need to get key value too which is 4 from list_code[4] in this case. How can I access that value?
or…
or…
or if there could be other unwanted numbers…
Or if you control the source, a good solution would be to use a
data-attribute for future HTML5 support……then in HTML5 browsers, you could do…
…or for legacy support, you could do…