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 trialJeremy Cox
9,300 PointsUsing text() method
I am getting a syntax error for how I have written this. I have also tried to write the class selector as ".profile-name" giving me the same error in what way am I not assigning the value correctly.
<!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>
$('button').click(function() {
var newName = $('#name-input').val();
$('#profile-name').text() = newName.val();
});
1 Answer
K Cleveland
21,839 PointsCheck this out:
var newName = $('#name-input').val();
$('#profile-name').text() = newName.val();
I can see some things that jump out at me. You saved the value from the selected name-input id into the newName variable, correct? So what is newName.val()?
Second, you said profile-name is a class. Is that that proper syntax for a class? And what's the proper syntax for .text()? Look back at the video and see differences from how .text() is used versus how you used it.
Also, I used const rather than var for my answer. Important to keep track of that.
You're really close. Good luck! :)
Jeremy Cox
9,300 PointsJeremy Cox
9,300 PointsThank You. I had it throw errors when I used the correct class selector at least 3 times so I guess I was kind of missing the forest for the trees.