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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:45:44+00:00 2026-06-10T00:45:44+00:00

i have the following jquery code. basically – it takes a value from an

  • 0

i have the following jquery code. basically – it takes a value from an anchor – and displays a sub-menu content below it.
this works perfectly.

$(function(){ 

    $('.plus').live('click', function(event){
        event.preventDefault();
        $(this).addClass('lower');
        var existingPath = $(this).attr('rel');

        GetSubs(this, existingPath);
        $(this).removeClass('plus').addClass('open');   //.delay(10000).removeClass('lower');
    });

    function GetSubs(IDclicked, existingPath){
        var dataString;
        dataString = 'lang=<%=Lang%>&rel=[' + existingPath + ']';


        $.ajax({
            type: "GET",
            url: "/includes/getSubCatMenuLinks.asp",
            data: dataString,
            success: function(data) {
                $(data).insertAfter(IDclicked);
            },
            error: function(obj,msg) {
                alert('*** Error! ***\n\n'+msg);
            }  

        });
    } 
});

what i would like to do – is have a a “loading” icon showing, while the content is loading – and then remove it when done.

displaying it is fine – thats whats done in the line

 $(this).addClass('lower');

when a few lines down, i try remove that class – but the movemext is so fast – that the loading icon doesnt even show.
ie – the ajax content hasnt appeared yet, but the jquery code has already loaded the class, loaded the ajax (somewhere) and then removed the class – so the loading icons doesnt even display.

i tried using the delay method – to have it removed a seconds or a few later – but it doesnt work.

any help appreciated!

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-06-10T00:45:46+00:00Added an answer on June 10, 2026 at 12:45 am

    delay() only works with animations, and not on functions like removeClass, for that you’ll need a timeOut. Not only that, but the Ajax call is asynchronous, so your class is removed instantly and does not wait for the Ajax call to finish.

    You could always do:

    $(function(){ 
        $(document).on('click', '.plus', function(e){
            e.preventDefault();
            var self = this,
                existingPath = $(this).attr('rel');
    
            $(self).addClass('lower');
    
            GetSubs(self, existingPath, function() { //added callback
                setTimeout(function() { //and a one second delay
                    $(self).removeClass('lower');
                }, 1000);
            });
        });
    
        function GetSubs(IDclicked, existingPath, callback){
            var dataString = 'lang=<%=Lang%>&rel=[' + existingPath + ']';
    
            $.ajax({
                type: "GET",
                url: "/includes/getSubCatMenuLinks.asp",
                data: dataString,
                success: function(data) {
                    $(data).insertAfter(IDclicked);
                },
                complete: function() {
                    callback.call(); //callback function is called when ajax is finished
                },
                error: function(obj,msg) {
                    alert('*** Error! ***\n\n'+msg);
                }  
            });
        } 
    });​
    

    This waits for the ajax call to finish, then waits one second, and then does the class stuff. Usually a timer just to show off your nice spinner is considered bad UI, so I would just keep the callback function.

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

Sidebar

Related Questions

I have the following jquery code: $(document).ready(function() { $(body[class*=page-calendar-practices] #content-header h1#title).after(<div id='athletics_practice-schedule'><div id='inner-title'><a href='www.example.com'
I have the following jQuery code: $(body.page-calendar-practices-2012-05 #content-header h1#title) which works fine. I can
I have the following jQuery code: $(ul.menu li a).click(function() { $(ul.menu li a).removeClass(currentMenu); $(this).addClass(currentMenu);
I have the following code: jQuery('#hexVal').change(function() { var hexvarval = jQuery('#hexVal').val(); jQuery('#thumbnail_hover_color').val(hexvarval); }); Basically,
I have the following code for the jQuery validation plugin.... basically on submit, I
i have the following jquery code. basically i will have several overlapped divs and
i have the following jQuery code. $(function() { $('.clickme').click(function() { $('.totalthing').slideToggle('slow','easeInOutQuart', function() { //
I have the following jquery code which doesn't work quite right when trying to
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following jQuery code which runs when I'm clicking an option in

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.