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

HTML

addClass() Jquery

This is question : "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." This is my answer : "var $submit = $('.submit-btn'); $submit.attr("disabled",true); $submit.addClass("disabled"); " And this is error i seen "Did you make a call to the "addClass" method after calling the "attr" method on the variable named "$submit"?" Can some body help me ?

Post your HTML and CSS code for better analysis.

5 Answers

Steven Parker
Steven Parker
242,770 Points

When "chaining", you call more than one method in the same statement. So, for these two separate statements:

$submit.attr("disabled",true);
$submit.addClass("disabled");

The chained version would look like this:

$submit.attr("disabled",true).addClass("disabled");

Thanks bro. I don't focus on "chain". So when i read question one more, my code worked, like you comment !

none of this works for me can anyone help me please ive been stuck on this for almost a week

Steven Parker
Steven Parker
242,770 Points

dturner — it might help to start a new question. Use the "get help" button if there's one on the page you are stuck on.

Are you sure this is right. I tried doing this, and it's still not working.

Steven Parker
Steven Parker
242,770 Points

It was right for the particular task he was working on. But since no link was given to the course page, you might be working on something with slightly different requirements. You might want to create a new question like I suggested to dturner.

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

yeh i get that thanks steven, but what I mean is $submit.attr("disabled",true); $submit.addClass("disabled"); Would this also be correct for the whole objective?

Steven Parker
Steven Parker
242,770 Points

For practical use, those two statements would perform the same functions. But for this particular exercise, the instructions said, "Chain the appropriate jQuery method ...".

Thanks Steven Parker.

What's the difference if you just said $submit.addClass("disabled"); instead of chaining the whole thing.

Steven Parker
Steven Parker
242,770 Points

The class only affects the appearance, but the attribute disables the button function.