JavaScript jQuery Basics Working with jQuery Collections Adding/Removing Classes

Daniel Flores
Daniel Flores
9,928 Points

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,860 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?

Antonio De Rose
Antonio De Rose
20,860 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,595 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?