Mazzy
Mazzy

Reputation: 1944

jQuery, select attribute from an input while looping

I'd like to pull an attribute value from the input

This is some of my html:

<input type="checkbox" name="invoice" client="14" value="53">
<input type="checkbox" name="invoice" client="14" value="54">
<input type="checkbox" name="invoice" client="17" value="52">

But I can't seem to be able to select anything, everytime I try to use a function while I'm eaching through them, is throwing undefined function

var inputs = $('input[name=invoice]');
    inputs.each(function(){
        console.log(this.attr('client'));
    });

Uncaught TypeError: undefined is not a function

while if I say this.value it returns 53, 54 and 52

Upvotes: 0

Views: 46

Answers (1)

T J
T J

Reputation: 43166

attr() is a jQuery method. this inside .each() refers to the native HTML element. You should make it a jquery object for calling jQuery methods like $(this).attr('client')

Upvotes: 1

Related Questions