Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Build an Interactive Website Form Validation and Manipulation jQuery Utility Methods

Trevor Wood
Trevor Wood
17,828 Points

Stuck on jQuery question

Not sure what I'm doing wrong here. Can anybody help out a little?

http://teamtreehouse.com/library/build-an-interactive-website/form-validation-and-manipulation/jquery-utility-methods

$('.required input').map(function(){
        values = $(this).val();
    return values;
});

2 Answers

Robert Newman
Robert Newman
29,571 Points

You need to create the var 'values' at the beginning.

var values = $(".required").map(function() { 
    return $(this).val();
});
Trevor Wood
Trevor Wood
17,828 Points

Ahh, okay I see how this works now. Thanks!

You only need to use .required as the selector and the jQuery map method returns a jQuery object, which contains an array, so you can assign the whole jQuery statement to the values variable like this .

Read more about it here

var values = $('.required').map(function(){   
    return $(this).val();
});