Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTrevor Wood
17,828 PointsStuck on jQuery question
Not sure what I'm doing wrong here. Can anybody help out a little?
$('.required input').map(function(){
values = $(this).val();
return values;
});
2 Answers
Robert Newman
29,571 PointsYou need to create the var 'values' at the beginning.
var values = $(".required").map(function() {
return $(this).val();
});
Jon Knight
7,184 PointsYou 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();
});
Trevor Wood
17,828 PointsTrevor Wood
17,828 PointsAhh, okay I see how this works now. Thanks!