Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6625541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:47:14+00:00 2026-05-25T21:47:14+00:00

I want to click on a button, a div appears, when clicking the same

  • 0

I want to click on a button, a div appears, when clicking the same button it should disappear.

Actually only appearing works, how to hide it again?

Skript:

$('#button').click(function() {
  $('#ui-block-a').removeClass('visuallyhidden').addClass('ui-block-a'), function(){
  $('#ui-block-a').addClass('visuallyhidden').removeClass('ui-block-a');
  };
}); 

HTML:

 <div class="visuallyhidden" id="ui-block-a">
     <ul data-role="listview" data-filter="true" id="nav"></ul> 
 </div>

Here is try to use a callback, but it is not working…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:47:14+00:00Added an answer on May 25, 2026 at 9:47 pm

    If the classes are correctly set from the beginning, you can use .toggleClass() [docs]:

    $('#ui-block-a').toggleClass('visuallyhidden ui-block-a');
    

    Otherwise, if you explicitly want to add/remove classes, you can use .toggle():

    $('#button').toggle(function() {
        $('#ui-block-a').removeClass('visuallyhidden').addClass('ui-block-a');
    
    }, function(){
        $('#ui-block-a').addClass('visuallyhidden').removeClass('ui-block-a');
    });
    

    Why your code does not work:

    You are not setting up a callback. You are executing two statements via the comma operator. The first part ($('#ui-block-a').addClass('...').removeClass('...')) will be executed as expected. The second part (function() {...}) will be evaluated as function expression and the result, a function, will be returned as overall result of the statement. But you are not assigning the result to anything, so it is just silently ignored.

    E.g. if you’d do

    // form is like `var foo = x, y;`
    var foo = $('#ui-block-a').removeClass('...').addClass('...'), function(){
        $('#ui-block-a').addClass('...').removeClass(...');
    };
    

    then foo would refer to the function

    function() { 
        $('#ui-block-a').addClass('...').removeClass('...');
    }
    

    But that is not what you want anyway. So putting a function there is legal, but has not special meaning and thus no effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After I click on a button div another div appears sliding down the screen
I have two tables on a webform. On a button click I want to
When click a button,I want to popup a view form bottom,like this! Any help
I want to add a click able button to a MKAnnotation as seen in
I want to be able to click a button and open a new form
I want to dismiss keyboard by click dismiss button ,How to build a bar
I have a form which I want to submit upon button click which is
I want to create a Toolbar in my application. If you click a button
I want to trigger on click of a button this: <asp:Button runat=server ID=submit Text=Submit
I don't want to allow user to double click on my button. On the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.