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

  • Home
  • SEARCH
  • 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 6924595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:40:57+00:00 2026-05-27T10:40:57+00:00

This is more a question of how would you go about doing this than

  • 0

This is more a question of how would you go about doing this than a specific problem.

Say i have 5 divs called div1, div2, div3, div4, div5. Whats the quickest/best way to make a looping function such as the one below that will loop a certain div (not all the divs on the page) if it is clicked.

Heres the best way i can think of explaining it.

Div1 is clicked. A function is called that checks div1 is listed as a div that should loop. Then starts the looping function. Div6 is clicked, but is not listed as a div that can loop and the function is not run.

function div1loop() {
        $("#div1").fadeTo("slow", 0.5, function ()    {
            $("#div1").fadeTo("slow", 0.1, div1loop);  
        });
}

Is there any way you could suggest that could the “#div1” part a variable so that i would not have to write 5 different functions for the 5 separate divs?

For a bit of background info –
Im going to end up having 50+ divs to do this for, and as you can imagine, it would save me a lot of time if i could make a function that could do this instead of 50.

Thanks!

  • 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-27T10:40:58+00:00Added an answer on May 27, 2026 at 10:40 am

    You can do it this way :

    function divloop(selector) {
       $(selector).fadeTo("slow", 0.5, function ()    {
           $(selector).fadeTo("slow", 0.1, function() { divloop(selector); });  
       });
    }
    

    Then :

    divloop("#div1");
    

    Edit :
    You’ve 2 options:

    1. Store selectors allowed in an array :

      var allowedDivs = ["#div1", "#div2", "#div3" ];
      

      and in divloop :

      function divloop(selector) {
          if(!$.inArray(selector, allowedDivs ) {
              return false;
          }
          $(selector).fadeTo("slow", 0.5, function ()    {
             $(selector).fadeTo("slow", 0.1, function() { divloop(selector); });  
          });
      }
      
    2. Or add a class to your div that you can check in your function

      <div id="div1" class="canLoop"></div>
      

      Then in your function :

      function divloop(selector) {
          if(!$(selector).hasClass("canLoop")) {
              return false;
          }
          $(selector).fadeTo("slow", 0.5, function ()    {
             $(selector).fadeTo("slow", 0.1, function() { divloop(selector); });  
          });
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is more about curiosity than utility. If I'm writing a function that's
This is more a question of pros/cons between PHP and JAVA. Iv been doing
ASP.Net MVC3 is cool and all but I have this question more out of
I'm not talking about making portable code. This is more a question of distribution.
This is more of a question about getting my head around the process I
This is more of a design question. I have a template class, and I
It's probably more a generic question about database, than a django one but let's
I have a question about optimization, but more on the browser/client side. I am
I know this question has been asked, but I can't find more than one
This question is more about the algorithm and the right use of function rather

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.