Javascript and the DOM


#1

Help please. I thought I did this correctly. It won’t let me pass with the unexpected function.


.active {
  background-color: #333333;
  color: whitesmoke;
  $('projects-button').toggleClass('active')
}


It says the $ sign is causing the problem. I don’t understand the challenge teaches me to do it that way who’s the wrong person now? ;-;


#2

$('projects-button').toggleClass('active') is jquery code, it should be in the javascript file

summary:
html is the structure of the a webpage
css can position and style the elements defined in html code

both html and css are rendered when page is loaded

jquery can manipulate both html and css after the document is rendered, this can be done by click events, scroll events and more.

html is defined in .html file, css is defined in .css file, jquery/javascript is defined in .js file. So your jquery code should go in .js file.


#3

Thank you. It helped now I can do it. I still wonder though, if that’s the case why don’t Codecademy at least give that clue to the hint/description? The instructions are pretty confusing since they told us to go inside the click in the css and write that. So they could at least tell us in the hint that we shouldn’t write it there.


#4

i need to see the instructions, can you provide a screenshot of the instructions?


#5

I can’t upload it the file said it can’t work. But here are the instructions:

.
In css/styles.css, there is this class:

.active {
background-color: #333333;
color: whitesmoke;
}
Inside the click function, toggle this class on the elements with the projects-button class.

The .active class will make the projects-button’s background dark and its text light.
Its pretty confusing but yeah I think that it says that.


#6

i think the instructions are fine, it says:

Inside the click function

css doesn’t have functions, so that is a clue to you.

Writing code is just a small part of programming, understanding and thinking about what you are doing is much more important, it will happen that you need to extract code from documentation and implement it slightly different in your program.

I think its good codecademy doesn’t explicitly state here that we need to switch to the js file, to make your think about it, and ensures you understand what you are doing, these thinking steps needs to be build into your routine.


#7

Ok ok thanks! Helps alot


#8