Need help with javascript and DOM lesson


#1

Hi,

I was working on my code in javascript and DOM lesson, exercise 11, "toggle class".
It kept correcting me even tho I was 100% sure my code was good so I pressed "Get code" to see where's my mistake.
After that, my code doesn't look like it used to be in last exercise, or this one. I tried restarting a few times, refreshing browser and closing it and starting lesson again. Even then, when I start exercise this code is here and I cannot progress.

function main() {
  $('.skillset').hide();
  $('.skillset').fadeIn(1000);
  
  $('.projects').hide();
  
  $('.projects-button').on('click', function() {
		$(this).next().slideToggle(400);
    $(this).toggleClass('active');
    $(this).text('Projects Viewed');
	});
}

$(document).ready(main);

I checked and $(this).... is from next exercise but there is no explanation in this one and it seems like it shouldn't be used here, at least it doesn't say so in instructions.

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.

$('.example-class').toggleClass('active');

Note: toggleClass does not require a . be added to the class you provide it within its parentheses. It is programmed to expect a class name.
2.

Click on the 'Recent Projects' buttons. Now they change color when clicked, and change back to their original state when clicked again.

There's still one big issue: we only want the element we clicked on to toggle its projects and class.

Let's solve it in the next exercise. Click 'Next' to continue."

Also, code doesn't work now, nothing happens with buttons when I click them.

How can i fix this, I am not able to learn anything further.

Thanks in advance


#2

you should do only what lessons expect.maybe you know but here you cant do what lesson doesnt want.
lesson 11
instruction:
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.

so you should use projects-button instead of this

$('.projects-button').toggleClass('active');


#3

I'm aware of that, bht the issue isn't what I have to do in lesson but my code like I said.


#4

This topic was automatically closed after 7 days. New replies are no longer allowed.