JavaScript jQuery Basics Working with jQuery Collections Adding/Removing Classes

James Steele
James Steele
2,816 Points

I get a strict mode error for my code below about a global variable?

My code to answer the task is as follows;

$submit=$(".submit-btn"); $submit.attr("disabled");

I get an error saying that strict mode prevents creation of a global variable which is $submit.

Is strict mode turned on in the treehouse environment? Is this something I can turn off I do I need to write my code differently?

1 Answer

Heidi Fryzell
Heidi Fryzell
Front End Web Development Techdegree Student 11,667 Points

Hi James,

There are a couple things I am noticing in your code. I think you want to use "const" to declare the variable, const will declare that variable and prevent it from being re-assigned, which is a good thing because you always want the variable to just select the class on the button and not change, like this:

const $submit = $('.submit-btn');

And you need to flag the "disabled" attribute as "true", like this:

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

Hope this helps! Heidi