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 trialSamantha Shugars
4,572 PointsI'm totally confused about which jQuery methods to use here
This is the first time I've had to stop and ask for help and I'm so frustrated! The question asks me to find a value in the DOM and set it to the input in a promt dialogue. I'm assuming I need to use a function, the .each() function specifically, because when I tried to select it with another method I got the error "'undefined' is not a function" or some such. I'm still getting this error using the .each() method, actually. No matter what I try I get the same error message. Over and over and over! Can anyone help me figure out what obvious thing I'm missing here?
//Show Prompt Window and store value
var fullName = prompt("What is your full name?");
//Select Input with the id of #fullName
("#fullName").each(function() {
var $anchor = $(this);
fullName.val($anchor.attr("value"));
});
//Insert value in to full name input
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<label for="fullName">Full Name</label><input id="fullName" name="fullName" value="" disabled>
<script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
2 Answers
sizwengubane
15,244 PointsHello, there is no shame in asking what you dont understand This is the correct code for the challenge <blockquotes>
//Show Prompt Window and store value
var fullName = prompt("What is your full name?");
//Select Input with the id of #fullName
$('#fullName');
//Insert value in to full name input
$('#fullName').val(fullName);
</blockquotes> First we are using a jQuery Selector to select an element with an id of 'fullName'. Next we are using the val() method to set the value of the selected element (in this case we are setting the element's value to the content inside the 'fullName variable') If you got it..mark my answer as the best
Jimmy Names
10,371 PointsThank you Lakindu! I too was over complementing this..
Samantha Shugars
4,572 PointsSamantha Shugars
4,572 PointsOh my gosh! I knew I was doing something wrong. Thank you so much! That's much simpler than the nonsense I was trying to fit in there.
sizwengubane
15,244 Pointssizwengubane
15,244 Pointsno problem, im always here to help u