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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:10:42+00:00 2026-06-04T19:10:42+00:00

I have the following JQuery which allows a user to select/de-select a list of

  • 0

I have the following JQuery which allows a user to select/de-select a list of items/prices as a way of creating an automatic quotation. The code looks like this:

$('table.products > tbody > tr').click(function(){
    if ($(this).find('div.price').is(":visible")) {
        $(this).find('div.price, img.selected').fadeOut(100);
    } else {
        $(this).siblings('div.price, img.selected').fadeIn(100);                    
    }
    recalc();
});

It’s actually more complicated than that (hence the reason I haven’t used toggle() but the above is just a simplified example for the purpose of this question.

Anyway, the above code works fine. If the table row is clicked then the price and image are either selected/de-selected depending on what they whether the price was already showing or not.

Then I have a call to a function called recalc(); at the end.. it looks like this (again, this is a simplified version):

function recalc() {
    var numOfProducts = $('table.products div.price:visible').length;
    alert(numOfProducts);
}

The problem I am having here is that the alert always returns the value that would have been correct before anything was changed.

For example, if there are no div.price visible and I select one, one will become visible but the alert shows 0. Then, if I select another one, that makes 2 visible but the alert only shows 1 because that’s what it was when I clicked. If I then click one of the items I already clicked in order to de-select it, it will display 2

So, my question is how am I supposed to ensure that the function call happens after everything else has been done?

  • 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-04T19:10:43+00:00Added an answer on June 4, 2026 at 7:10 pm

    I have come to the conclusion that my approach is completely wrong. I’m basing this partly on the fact that not many people have suggested answers to this question and also partly because the answers I have received don’t accomplish what I’m trying to do. Perhaps my explanation wasn’t clear enough, too.

    So, my solution to my original question of getting an accurate report of the number of selected product rows is to create a global variable in JS as so:

    window.config =
        {
            products : 0,
        };
    

    Then, add lines to the if statement to increment or decrement the variable depending on what happened:

    $('table.products > tbody > tr').click(function(){
        window.config.products = window.config.products - 1; // Decrement
        if ($(this).find('div.price').is(":visible")) {
            $(this).find('div.price, img.selected').fadeOut(100);
        } else {
            window.config.products = window.config.products + 1; // Increment
            $(this).siblings('div.price, img.selected').fadeIn(100);                    
        }
    });
    

    Now I have an accurate record of the number of selected products in the global variable which I can access at any time to continue the development of my application.

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

Sidebar

Related Questions

I have the following code which only allows users to select Mondays from jquery
I have the following jQuery which I want to output a list of images.
I have the following jQuery code which runs when I'm clicking an option in
I have the following code which gets the id of the currently selected jquery-ui-tab:
I have the following JavaScript code which I like to convert to jQuery but
I have the following JQuery code which does similar functionality like Stackoverflow where the
I have the following method which allows a user to login into my application:
Using the jQuery Cycle plugin, the following code allows user to browse the photos/:
I have the following jQuery which I need adapting: $(document).ready(function(){ $(.rss-popup a).hover(function() { $(this).next(em).stop(true,
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(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.