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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:36:54+00:00 2026-05-26T10:36:54+00:00

In regard to the following function, which I’ve rewritten a dozen times over the

  • 0

In regard to the following function, which I’ve rewritten a dozen times over the last hour:

function show_history() {
    $('.job.collapsed').click(function() {
        $(this).removeClass('collapsed');
        $(this).addClass('expanded');
        $(this).children('.bottom').load('expand.php', function(){
            $('.job.expanded').click(function() {
                $(this).removeClass('expanded');
                $(this).addClass('collapsed');
                $(this).children('.bottom').html('');
                $(show_history);
            });
        });
    });
}

Which I initially call as such:

$(document).ready(function() {
    $('#main').load('jobs.php', show_history);
});

The 1st time I click a ‘.job’, 1 request is sent to ‘expand.php’

The 2nd click also sends 1 request to ‘expand.php’, despite the ‘.job’ not having the ‘.collapsed’ class.

The 3rd click sends 2 requests, the 4th sends 3 requests, the 5th sends 6 requests, the 6th sends 9 requests, the 7th sends 18 requests, the 8th sends 27 requests, etc.

I would like it send 1 request when clicking a collapsed job, and no requests when I click an expanded job.

How can I fix this?

EDIT

The solution I used, based on @mblase75’s suggestion:

function show_history() {
    $('.job.collapsed').live('click',function() {
        $(this).removeClass('collapsed');
        $(this).addClass('expanded');
        $(this).children('.bottom').load('expand.php');
    });
    $('.job.expanded').live('click',function() {
        $(this).removeClass('expanded');
        $(this).addClass('collapsed');
        $(this).children('.bottom').html('');
    });
}
  • 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-26T10:36:55+00:00Added an answer on May 26, 2026 at 10:36 am

    Try moving your .click out of the callback and replace it with a .live("click") handler:

       $('.job.expanded').live('click',function() {
            $(this).removeClass('expanded');
            $(this).addClass('collapsed');
            $(this).children('.bottom').html('');
            $(show_history);
       });
       $(this).children('.bottom').load('expand.php');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what is the difference between following function declarations, which create and return the array
I have a file which contains lines of the following format: w1#1#x w2#4#b w3#2#d
I have an expensive function defined in a base class, which depends on low
Say you have the following piece of code: function someProcess() { var deferred =
I have the following code: var string = word1;word2;word3,word4,word5,word6.word7; function ends_with(string, character) { var
Consider the following Javascript function (1): function setData(domElement) { domElement.myDataProperty = { 'suppose': 'this',
I were asked to analyze an assembly code, which was generated from following c++
I have the following method which allows a user to login into my application:
I have the following Ajax call which send form data to a page and
Taking the following Model: MyModel= Backbone.Model.extend({ defaults : { myNestedModel:undefined, }, initialize: function() {

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.