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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:44:57+00:00 2026-05-29T14:44:57+00:00

//this counts how many images exist var img_count = $(#gallery_scroller img).length; //this is a

  • 0
  //this counts how many images exist
  var img_count = $("#gallery_scroller img").length;
  //this is a number where I want the clicks to stop working
  var limit_count = img_count/3;

  var click_count = 1;

  if ( limit_count > click_count){

    $("#down_arrow").click(function(){
      click_count++
      var css_position = -1*click_count*300;
      $('#gallery_scroller img').css('top', css_position);
      alert(css_position+' '+limit_count+' '+click_count);
    });
  };

I put the alert at the end so I can observe the values everytime I click. It just keeps on going even though the click_count is larger than the limit_count. In the if condition, when I replace click_count with an actual number that is larger than the limit_count it works.

  • 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-29T14:45:01+00:00Added an answer on May 29, 2026 at 2:45 pm

    Your if statement isn’t in the code in the click event handler. Once the handler is attached, only the code within the handler will get run when the click occurs.

    I’m not entirely sure what your desired result is, but this is probably closer:

    //this counts how many images exist
    var img_count = $("#gallery_scroller img").length;
    //this is a number where I want the clicks to stop working
    var limit_count = img_count/3;
    
    var click_count = 1;
    
    $("#down_arrow").click(function(){
        if ( limit_count > click_count){
            click_count++;
            var css_position = -1*click_count*300;
            $('#gallery_scroller img').css('top', css_position);
            alert(css_position+' '+limit_count+' '+click_count);
        }
    });
    

    E.g., put the test within the event handler code.


    Side note: There’s no need for a semicolon at the end of the curly braces on an if block, e.g.:

        if (...) {
        };
    //   ^--- no semi here
    

    Side note 2: I’ve added a semicolon after click_count++. Without it, you’re relying on the horror that is automatic semicolon insertion. You were okay because there was a line break after it, but in general, best to learn the rules of where semicolons go and always include them where they’re required.

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

Sidebar

Related Questions

I have many folders of images, and I want to create a batch file
i want to display many images like thumbnails in a scroll view and and
Not sure if this counts as programming related, it's a tool that I use.
How do I count only the files in a directory? This counts the directory
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I
This is an offshoot of this question: Chrome counts characters wrong in textarea with
I wrote this script which counts occurrences of particular pattern in a given file.
This issue came up when I got different records counts for what I thought
I was using this method to get row-counts for SELECT statements, but it didn't
This is the snippet of code i'm using now: def countOccurences(a, b) #counts the

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.