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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:05:53+00:00 2026-05-21T05:05:53+00:00

Heres the code $(‘#print’).click(function(){ $(‘#compatibility h2’).each(function(){ var clicked = $(this); if($(this).hasClass(‘collapsed’)) { $(clicked).removeClass(‘collapsed’); if($($(this)[0].nextSibling).is(‘ul’))

  • 0

Heres the code

    $('#print').click(function(){
        $('#compatibility h2').each(function(){
                var clicked = $(this);
                if($(this).hasClass('collapsed'))
                {
                    $(clicked).removeClass('collapsed');
                    if($($(this)[0].nextSibling).is('ul'))
                    {
                        $(this).next().slideToggle();
                    }
                    else
                    {
                    $.get("getproducts.php", {cid: $(this).attr('id'), did: $("#deviceId").val()},
                          function(data)
                          {   
                            $(clicked).after(data).next().slideToggle(); //adds a <ul> <li> </li> </ul>  
                          });
                    }
                }
            });

        $('#expandCollapse').attr('value','Collapse All');
        print();        
});

here is what the function of print does

example of what it does

It doesnt wait for the toggle to fully complete before trying to do the print command anyone have any ideas to fix this?? 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-21T05:05:54+00:00Added an answer on May 21, 2026 at 5:05 am

    You have a lot of asynchronous tasks (animations and AJAX calls) triggering when you call each(...). Because they’re asynchronous, JavaScript won’t wait for them to finish before finishing the rest of the tasks in your click handler.

    The solution is to count how many asynchronous tasks you have to start with, and then decrement by one each time one completes. When you reach zero, all tasks are finished and you can call print() safely knowing all asynchronous work is done.

    Disclaimer: I haven’t tested this code, but it should work. If not, this should give you enough to get the right idea.

    $('#print').click(function(){
        var titles = $('#compatibility h2'),
            titlesLeftToProcess = titles.length;
    
        function finishedToggling() {
            titlesLeftToProcess--;
            if (titlesLeftToProcess < 1) {
                print();
            }
        }
    
        titles.each(function() {
            var clicked = $(this);
            if(clicked.hasClass('collapsed')) {
                clicked.removeClass('collapsed');
                if(clicked.next().is('ul')) {
                    clicked.next().slideToggle(finishedToggling);
                } else {
                    $.get("getproducts.php", 
                        {cid: clicked.attr('id'), did: $("#deviceId").val()},
                        function(data)
                        {   
                            clicked.after(data).next().slideToggle(finishedToggling);
                        });
                }
            }
        });
    
        $('#expandCollapse').attr('value','Collapse All');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
Heres my code: XElement navegacion; public Navegacion() { this.navegacion = XElement.Load(HttpContext.Current.Server.MapPath(App_Data/navegacion.xml)); } It works
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
Heres the code I've made up so far. Its fully functional and the only
heres my code: start /realtime /b /wait .\jampDed.exe for /f tokens=1-5 delims=: %%d in
Heres the code for converting the json retured date to a string of date.
Heres some code for a test case. I don't understand why the first two
Heres my code: data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5],
Heres my code: void *PrintLine(void *line) { printf(Line: #%s\n, (char *)line); pthread_exit(NULL); } int
Heres my code <?php session_start(); include('config.php'); if(isset($_GET['search_word'])) { // echo $_GET['search_word'] . '<br />';

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.