javascript - can any one help me with this jquery code , i want to console the array out side the loop? -
$('#list').click(function(){ var val = []; $(':check box:checked').each(function(i){ val[i] = $(this).val(); }); console.log(val); });
can 1 me jquery code , want console array out side loop !! tried many options ,no success ,please me
i want print array out side click function
as said in comment, need make val
not local variable. can moving declaration outside of closure.
val = []; $('#list').click(function(){ val = []; $(':checkbox:checked').each(function(i){ val[i] = $(this).val(); }); console.log(val); });
Comments
Post a Comment