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 trial

JavaScript jQuery Basics Introducing jQuery Getting Values from Form Fields

JQuery Basics: Getting values from form fields Task 2

Not sure what I am doing wrong. The bummer states, "Within the anonymous function passed to the "click" method call, did you supply the argument "newName" to the "text" method call on the jQuery object with an argument of "'.profile-name'"?"

I am getting confused over the wording since the bummer/hint seems to ask did I added the .text to the var newName, which I did not. I added it to the profile-name class.

In addition, the last part "... set the content of .profile-name to the value of the input field" is confusing too. Is this part just saying to add type in "Treasure Porth" even though it's already in the html file? Or is it saying when I add in the .text() method to just leave the inside of .text blank?

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <h2 class="profile-name">Treasure Porth</h2>
    <p class="profile-text">I am a web developer!</p>

    <label>Change name:<input id="name-input" type="text"></label>
    <button>Change</button>

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
$('button').click(function() {
  var newName = $("#name-input").val()
  $(".profile-name").text()
});

2 Answers

The syntax to set the text content is:

$(selector).text(content)

For the challenge content refers to newName. This variable stores the value of the name input field which you completed in the previous task. So you would pass newName to the text method as follows:

$(".profile-name").text(newName)

Tell me why I added newName into the text prior to asking for help, but I put newName in parentheses. OMG, silly mistake. Thank you for your help.