Donatas Veikutis
Donatas Veikutis

Reputation: 1004

jquery each function error when getting value

I have that Jquery code:

$('input[name*="fotos[]"]').each(function (i, ele) {
      alert(ele.val());
});

but I get that error in browers:

Error: TypeError: ele.val is not a function

what is wrong here?

Upvotes: 1

Views: 934

Answers (3)

rahul
rahul

Reputation: 7663

you can use

alert($(ele).val());

or

alert($(this).val());

Upvotes: 3

Alnitak
Alnitak

Reputation: 340045

The ele parameter to the .each callback is a single DOM element, not a jQuery object.

You should either:

  1. use the native DOM property - ele.value, or

  2. convert ele back into a jQuery object - $(ele).val()

NB: within the callback, this === ele

Upvotes: 2

codebox
codebox

Reputation: 20264

You need to turn ele into a jQuery object:

alert($(ele).val());

Upvotes: 2

Related Questions