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 Using text() and html()

Problems in changing the content of the element in jQuery

Hi there, I need help to take a look at my code. I can't seem to get it right. When I did a preview, it works fine. Thank you in advance.

This is was my code challenge: You've just learned how to use the jQuery methods text() and html(). Use the appropriate jQuery method to set the contents of the $('.profile-text') element to "I am a web developer".

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <h1 class="profile-header"></h1>
    <p class="profile-text"></p>

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
jQuery('.profile-text');

const contents = "I am web developer";
$('.profile-text').html(contents);

2 Answers

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 38,105 Points

Hi Marni. While your code would work these challenges can be very picky. First of all remove your const contents and paste the string directly in the html(). And second and the one that took me a few minutes to find was in the string you are missing 'a'. It should be "I am a web developer". Keep at it! These challenges are picky but help you be more exact and improve your debugging skills.

Hi Mark, Thank you for your help and reply. I did what you suggested by removing and pasting. But the same error still appears.

jQuery('.profile-text');
const contents = "I am a web developer";
$('.profile-text').html(contents);
Mark Sebeck
Mark Sebeck
Treehouse Moderator 38,105 Points

Move your string into the HTML. Don’t use the const contents.

$('.profile-text').html(β€œI am a web developer”);