Reputation: 9299
If I run this code in Firebug everything goes fine and works:
var ingarray =$(".ingsparts");
$.each(ingarray ,function(n){
var ing = ingarray[n];
console.log($(ing).find('.name').val());
console.log($(ing).find('.value').val())
});
but if I run this, it doesn't work:
var ingarray =$(".ingsparts");
$.each(ingarray ,function(n){
var ing = ingarray[n];
var in = $(ing).find('.name').val();
var ms = $(ing).find('.value').val();
});
Upvotes: 0
Views: 65
Reputation: 814
Yeah, dont use in as variable name, but also, your each can be done more simply:
var ingarray = $(".ingsparts");
ingarray.each(function(){
var name = $(this).find('.name').val();
var value = $(this).find('.value').val();
...
});
Upvotes: 1
Reputation: 14808
in
is a reserved word in Javascript (see here for more info), you will have to rename this variable.
Upvotes: 3
Reputation: 75659
The second example defines the in and ms variables inside the function. This means that they get function scope and are not usable outside of the function. So the variables are set, but never used and not accessed.
Upvotes: 0