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 7845773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:21:23+00:00 2026-06-02T17:21:23+00:00

I got a div element, so when I click on it, another div which

  • 0

I got a div element, so when I click on it, another div which is hidden by default is sliding and showing, here is the code for the animation itself:

$('#myelement').click(function(){
     $('#another-element').show("slide", { direction: "right" }, 1000);
});

How can I make that so when I click on the #myelement one more time (when the element is showed already) it will hide the #another-element like this:

$('#another-element').hide("slide", { direction: "right" }, 1000);?

So basicly, it should work exactly like a slideToggle but with the show/hide functions. Is that possible?

  • 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-06-02T17:21:25+00:00Added an answer on June 2, 2026 at 5:21 pm

    The toggle-event is deprecated in version 1.8, and removed in version 1.9

    Try this…

    $('#myelement').toggle(
       function () {
          $('#another-element').show("slide", {
              direction: "right"
          }, 1000);
       },
       function () {
          $('#another-element').hide("slide", {
              direction: "right"
          }, 1000);
    });
    

    Note: This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. jQuery also provides an animation method named
    .toggle() that toggles the visibility of elements. Whether the
    animation or the event method is fired depends on the set of arguments
    passed, jQuery docs.

    The .toggle() method is provided for convenience. It is relatively
    straightforward to implement the same behavior by hand, and this can
    be necessary if the assumptions built into .toggle() prove limiting.
    For example, .toggle() is not guaranteed to work correctly if applied
    twice to the same element. Since .toggle() internally uses a click
    handler to do its work, we must unbind click to remove a behavior
    attached with .toggle(), so other click handlers can be caught in the
    crossfire. The implementation also calls .preventDefault() on the
    event, so links will not be followed and buttons will not be clicked
    if .toggle() has been called on the element, jQuery docs

    You toggle between visibility using show and hide with click. You can put condition on visibility if element is visible then hide else show it. Note you will need jQuery UI to use addition effects with show / hide like direction.

    Live Demo

    $( "#myelement" ).click(function() {     
        if($('#another-element:visible').length)
            $('#another-element').hide("slide", { direction: "right" }, 1000);
        else
            $('#another-element').show("slide", { direction: "right" }, 1000);        
    });
    

    Or, simply use toggle instead of click. By using toggle you wont need a condition (if-else) statement. as suggested by T.J.Crowder.

    Live Demo

    $( "#myelement" ).click(function() {     
       $('#another-element').toggle("slide", { direction: "right" }, 1000);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an element inside a div which has a click event associated to
I’ve got a function that appends a <div> to an element on click. The
Here's my scenario: I've got a div on Page A. When an event happens
i've got this $('#div').attr(hidden, true); i tried: var a = $('#div').attr(hidden); var b =
I got a red square (DIV) and everytime I click on it I like
I have a div element. I need to catch a mouse click on this
Hello I got problem with scroll on my grid. Here is the code (nothing
I'm creating a new element in Mootools which has events, thus: var div =
Possible Duplicate: Get image data in Javascript? Hello, I've got a single div, which
I've got the following code: <div onclick=alert('div event'); style=cursor:pointer> some text <a href=asd.php id=link>click</a>

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.