I try to use each() function on my DOM to get field dynamically added. But I hava a probleme with this code :
var nouvelle_entree=new Object();
$('div[name="declaration-ligne-entree"]').each(function () {
nouvelle_entree.name=$(this).children('input[name="system-input-name"]').val();
nouvelle_entree.values=$(this).children('input[name="system-input-valeur"]').val().split(",");
console.log(nouvelle_entree);
mockSystem.input.push(nouvelle_entree);
});
console.log(mockSystem.input);
The push function always push the last child and not the other but on my console log in have the good values.
log 1 : {name: "a", values: Array(1)}
log 2 : {name: "b", values: Array(1)}
log 3: [
{name: "b", values: Array(1)}
{name: "b", values: Array(1)}
]
Why ?