So I have a jQuery code which on a button click logs the values of every input field on my page:
I have tried this method with forEach method on inputs but it says it' not a function, why can't I use this method here?
$("#submit").click(e => {
e.preventDefault();
let inputs = $("input");
inputs.each(() => {
console.log($(this).val());
});
});
But the problem here is that the this keyword here refers to #submit
, How could I achieve my goal here using only the this keyword , and why is this here referring to #submit
and not the input
?
Thanks in advance.