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

  • Home
  • SEARCH
  • 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 7032167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:53:57+00:00 2026-05-28T00:53:57+00:00

I’m trying to work on a toggle a div element currently has some information

  • 0

I’m trying to work on a toggle

a div element currently has some information and when a user clicks a link, it will slide up, and slide down with new information.

I’m working on ajax so when user clicks on the link, the new information that appears is coming from another page.

('a').toggle(function(){
    $('.content').slideUp("fast");  
    $.ajax({
        type: "GET",
        url: "URL",
        data: data,
        success: function(data){
                $('.element').delay("slow").slideDown("fast").html(data);
        }
    });
},function(){
    $('.element').slideUp("slow");
    $('.content').delay("slow").slideDown("slow");

});


<div class='content'>
old information
</div>
<div class='element'>
New information from another page, being shown through ajax
</div>

Thats the basics of my script. Right now when I click on the link, the new information shows right away before the old information gets to slide up.

Any thoughts or ideas on how I should go about this? Maybe a better way to write this?

Also, is there a way to remove the .html(data)? so when I slide back to the original folder, it’ll disappear? Or would I just have to use the .hide() function? Maybe .remove()?

Thanks!

  • 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-28T00:53:58+00:00Added an answer on May 28, 2026 at 12:53 am

    It sounds like you might want to use the callback on your slideup. It will run the callback function once the slideup function is complete.
    So something like this:

    $('a').toggle(function(){
        $('.content').slideUp("fast", function(){
            $.ajax({
                type: "GET",
                url: "URL",
                data: data,
                success: function(data){
                    $('.element').delay("slow").slideDown("fast").html(data);
                }
            });
        });
    

    Although the drawback of that is it wouldn’t load results through AJAX until after the slideup happens, which has the possibility if making you wait an additional length of time, however, it doesn’t sound like waiting the problem, so that might be all you need.

    If I were running into the same issue it sounds like you’re running into, I would probably create 2 variables, one to hold the slideup state and one to hold the HTML returning from AJAX.
    I would then make both the ajax success callback and the slideup callback run a function that would insert the HTML and slide down if 2 conditions are met: 1) the slideup is completed and 2) the AJAX request has returned a result.

    This way, both the request and the slideup/slidedown will work together as fast as possible but without overlapping.

    // here's an example of the function you would have both slideUp and ajax success callbacks run
    var $html,
        $slide = false; // false indicates we're not in the process of a slideup
    
    function process_data()
    {
        // only process the slidedown if we're not in the process of a slideup and we have the html we're after
        if (!$slide && $html)
        {
            $('.element').slideDown('fast').html($html);
            // make sure to empty $html afterwards so we don't assume we have data next time this runs
            $html = '';
        }
    }
    

    so your slideup would include the above function in the callback

    $slide = true;
    $('.content').slideUp('fast', function(){
         // the slideup is completed, so set the slide back to false
         $slide = false;
    
        // process data
         process_data();
    });
    

    and your ajax success would also use process_data

    success: function(data){
        // store the returning data in the html variable
        $html = data;
    
        // process data
        process_data();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.