2

This looks awkward but when I'm trying to add any class or remove any class using jQuery it's not working, Instead of adding or removing class I tried with the alert window, in that case, it's working fine. Can anyone tell me why I'm not able to add or remove any class?

$('#sign').click(function(){ alert("I'm working"); $('#signup').ready(function(){ $(this).addClass('hidden'); }); }); 

This is the code I've tried and #sign is the id in Sidebar or navbar whatever. When I click on that link then it goes to the section with id #signup. In this section I want that class to add or remove.

2
  • 2
    remove $('#signup').ready(function(){ and use $('#signup').toggleClass('hidden');. Complete Code is: $('#sign').click(function(){ $('#signup').toggleClass('hidden'); }) Commented May 29, 2020 at 6:43
  • ready make no sense in this context (no trigger) Commented May 29, 2020 at 7:49

1 Answer 1

1

See: https://api.jquery.com/ready/

$('#signup').ready(...) does not seem applicable. The page is already loaded, so you do not need to wait for DOM ready. Just remove that wrapper and manipulate the class directly:

$('#sign').click(function(){ alert("I'm working"); $('#signup').addClass('hidden'); }); 

I am assuming you are trying to handle clicking on and changing the classes on DIFFERENT elements (despite the similar names).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.