Can you remove the class on which you selected an element?

Question

In the context of this exercise, can you remove the class on which you selected an element?

Answer

Yes, you can remove the class from the element you selected them on. For example, you can do the following,

$('.className').removeClass('className');

It is important to keep in mind that once you remove a class, you cannot select it again using that class name, and to reapply it to an element, you must select it using another attribute.

4 Likes

In this https://www.codecademy.com/paths/web-development/tracks/learn-jquery/modules/learn-jquery-style-methods/lessons/jquery-style-methods/exercises/remove-class I do not see the visual effect of $(’.nav-menu’).removeClass(‘hide’); after commentint it out, The webpage still behaved the same.

2 Likes

What the previous poster said is correct; to clarify, at the start of the exercise the nav-menu displays when you hover over the menu-button even though the nav-menu has the ‘hide’ class ( class=“nav-menu hide”), so removing the ‘hide’ class doesn’t appear to have any visual effect, I think this is because in the event handler, ‘show()’ is called on the nav-menu before removeClass().

1 Like