2

I want to show next five divs each time when i click show more button, 5 divs will be shown default when load, here is my code,

var counterBox = 5;
$("#show_more_location").click(function() {
    $(".loading-container").show();
    for (var inc = 5; inc <= 5; inc++) {
        if(counterBox<50){
            counterBox = counterBox + 1;
            $(".location-box:nth-child("+counterBox+")").slideDown().addClass("show_box").delay(100);
        }  
    }
    $(".loading-container").delay(5000).hide();         
});

Problem is that when I click show more button, it loops only once, and stops. Only one div is showing ,I want to show 5 divs on show buttonclick.

Can anyonehelp?

5
  • 1
    If your loop counter starts with the value 5, then don’t expect it to be lesser than or equal 5 after you added a positive value to 5 ... Commented Aug 28, 2017 at 13:03
  • The risks of copy pasting a var decleration... Commented Aug 28, 2017 at 13:04
  • thnx @CBroe, its because of lot of work, just initialize inc = 0, it works fine, thnx again Commented Aug 28, 2017 at 13:08
  • @MuhammadAkberKhan Then you should accept OddBrew's answer. Commented Aug 28, 2017 at 13:09
  • and one more thing is loading div is not showing/hide, its executing very fast, i have also add delay of 5 sec but loading is not showing Commented Aug 28, 2017 at 13:13

2 Answers 2

3

It seems you init your inc iterator with 5, and get out of the loop when it's higher than 5:

for (var inc = 5; inc <= 5; inc++) {
   ...
}

Try initializing it with 1:

for (var inc = 1; inc <= 5; inc++) {
   ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

but one more point can you help, loading div is not showing, as i have also add the delay in hide, check my question, i have update
@MuhammadAkberKhan did you try with the function setTimeOut() instead ? Check out its usage here w3schools.com/jsref/met_win_settimeout.asp
0

You're setting inc in the for loop to 5, then checking if it is lower than or is 5. So it runs once. Make inc 0 to run it 6 times.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.