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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:33:18+00:00 2026-06-01T05:33:18+00:00

I have some items that I’d like the user to be able to filter

  • 0

I have some items that I’d like the user to be able to filter using jQuery. The user selects their filter criteria and hits submit, and I make a call to my database. When this call completes, I fade out the existing containers with this function:

function clearGrid() {
    var theseDivs = $('.grid-item');
    $('.grid-item').fadeOut('fast', function() {
    $(theseDivs).remove();      
    }); 
}

and then I append my new data with the following function:

function repopulate() {
    <% @stuff.each do |gb| %>
    $('#grid').append('<%= escape_javascript(render "/stuff", :gb => gb) %>');
    <% end %>
    resizeGrid();
}

The resizeGrid() function does some absolute positioning based on the other elements in the Grid. It seems like repopulate() is being called BEFORE the other elements are removed with clearGrid(), and thus the positioning of the new elements is off, and they’re rendered as if the old elements are still there.

Is there a way to ensure that my repopulate() function doesn’t get called until the other elements are well out of the way?

  • 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-01T05:33:20+00:00Added an answer on June 1, 2026 at 5:33 am

    You should allow the clearGrid() function to call a callback once it’s completed, and then pass it repopulate as that callback. Change clearGrid() to look like this:

    function clearGrid(callback) {
        var theseDivs = $('.grid-item');
        theseDivs.fadeOut('fast', function() {
            theseDivs.remove();
            if(callback) {
                callback();
            }
        }); 
    }
    

    And then, assuming your current code to call those two looks like this:

    clearGrid();
    repopulate();
    

    You can change it to look like this:

    clearGrid( repopulate );
    

    Note: repopulate should not have () after it because you want to pass a reference to it, not call it.

    Second note: I also changed clearGrid() to just use theseDivs rather than call jQuery again. It’s slightly faster this way, although you probably won’t be able to notice the difference.

    If you know that there will only ever be <div> tags that you’re working with, you could change the selector to $('div.grid-item') for another small speedup.

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

Sidebar

Related Questions

I have some items in my .emacs that I don't want to run if
I have written some code to ensure that items on an order are all
i have some Orders that can have several Items and these Items have an
Right now I have a JSP page that allows to sort some items, when
I have some items that change the UINavigationBar color when the detail pages are
I have a list of items that have some jQueryUI buttons associated with them.
I have a some items that I want to partition in to a number
I have some items for sale that have 2 and 3 levels of customization.
I have a listview with some items that can be marked as done. There
I have a DropDown menu with some items that should be accessible only after

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.