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

Shaun Wong
Shaun Wong
14,489 Points

Select the submit button by its class and save it to a variable called $submit....

Challenge Task 1 of 2 Select the submit button by its class and save it to a variable called $submit. Then use the appropriate jQuery method to disable the button by adding a disabled attribute to it.

Will not validate, what have i done wrong here?

https://teamtreehouse.com/library/jquery-basics-2/working-with-jquery-collections/addingremoving-classes

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
var $submit = $('.submit-btn');
$submit.attr("disabled","true");
Shaun Wong
Shaun Wong
14,489 Points

I tried .attr("disabled", "disabled");

as well.

4 Answers

Shaun Wong
Shaun Wong
14,489 Points

Oh hang on, I see. True should not be in " quotes " as it's not a string but a boolean. However. I may have gotten confused when I was browsing and saw .attr("disabled", "disabled");

The error that came up told me to use true instead but would not validate.

Nevertheless... Answer below for anyone who gets stuck.

not-porn-app.js
var $submit = $('.submit-btn');
$submit.attr("disabled",true);

Thank you Shaun Wong. I had been stuck on that one for several days.

Sean Flanagan
Sean Flanagan
33,235 Points

Thank you Shaun. That's a big help!

not-porn-app.js?????

Randell Purington
Randell Purington
9,992 Points

Thank you for the help, but I am wondering what other app.js there are.lol

Yep! Same mistake here. Thanks!

Midhun Chandran
Midhun Chandran
9,414 Points

const $submit = $('.submit-btn'); $submit.attr("disabled",true);

The above worked for me. It is same as what shaun wong suggested. The only difference being that i used const instead of var.

Hope this helps. Thanks!

Nnanna Okoli
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nnanna Okoli
Front End Web Development Techdegree Graduate 19,181 Points

I got everything right except for using the word "const" instead of "var"

However, both codes were passed! (eg.) const $submit = $('.submit-btn') $submit.attr("disabled", true);

I would like to add that Treasure Porth's teachings is like a breath of fresh air as she is the light at the end of the tunnel lol.. keep going guys. Lastly, if someone could help why both codes were passed AND why would we need to use 'var' instead of 'const' to save our change to a variable?