1

I am getting all form elements which have the name attribute and I need to get the name. So I have;

$form.find("input[name], textarea[name]").each(function (index, value) {
  console.log(value.attr("name"));
})

But I get the error:

TypeError: value.attr is not a function

What am I missing?

2 Answers 2

4

You need to convert element i.e. value to jQuery object.

$form.find("input[name], textarea[name]").each(function (index, value) {
  console.log($(value).attr("name"));
})
Sign up to request clarification or add additional context in comments.

Comments

3

Please try with this:

$form.find("input, textarea").each(function (index, value) {
  console.log($(value).attr("name"));
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.