Reputation: 33
If I click add button then the same for will added next to the previous. I wan to get the values of input fields of each forms using each()
function. I tried running below code.
$('.question-div').each(function(i) {
//to get Degree field value.
console.log($(".question_Degree_0").val());
});
The problem is like this way I only get two times the same value of the first form's Degree value. For example if I select 1 in first form, and if I add one more form, the second time also get the value '1' in Degree value though I select different value.. My question is what can I do so that I can get values of input fields using each()
function?
Thank you.
Upvotes: 0
Views: 98
Reputation: 161
I have executed the piece of code and the solution is as below
$('input').each(function(ele) { console.log($(this).val()); });
Upvotes: 0
Reputation: 760
Try this,
$('input').each(function(i) {
console.log($(this).val());//to get all the input value.
});
Upvotes: 0
Reputation: 21628
Try using
$(".question_Degree_0", this).val()
inside your loop function.
or
$('.question-div .question_Degree_0').each(function(i) {
console.log($(this).val());
});
Upvotes: 2