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 Working with jQuery Collections Adding/Removing Classes

I am stuck on this part of the challenge.

The submit button is now disabled, but it doesn’t look like it! Luckily, we have a class called disabled in our CSS that will style it for us. Chain the appropriate jQuery method to add the class of disabled to the submit button.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <button type="submit" class="submit-btn">Submit If You Can</button>

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
const $submit = $('.submit-btn');
$submit.attr('disabled', true);
$submit.addClass('disabled');
$submit.attr('disabled', true).addClass('disabled');

2 Answers

Antonio De Rose
Antonio De Rose
20,885 Points

yes, I am sure this is the answer, above my post is the explanation, on someone's effort. below is the straight away answer

const $submit = $('.submit-btn');
$submit.attr('disabled', true).addClass("disabled");
J llama
J llama
12,631 Points

This is besides the point, but as a js noob, isn't const not the correct variable type to use here? Aren't we changing const $submit by manipulating the submit-btn's attributes?

Antonio De Rose
Antonio De Rose
20,885 Points
const $submit = $('.submit-btn');
$submit.attr('disabled', true); <!--what needed from here, to chain the method, from here.-->
$submit.addClass('disabled'); <!--this line is not necessary, as per to the question.-->
$submit.attr('disabled', true).addClass('disabled'); <!--this line too not necessary.-->

<1--css has the class it mentions, you have to bring the class to the DOM-->
<!--check on addClass in jQuery-->
Khaleel Jones
Khaleel Jones
13,783 Points

Are you sure this is the right answer?