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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:50:29+00:00 2026-05-15T22:50:29+00:00

I have a for function performed in a jQuery draggable function. Is there a

  • 0

I have a “for” function performed in a jQuery draggable function. Is there a better way to do this from the execution time perspective? My function is:

 $("#dragger").draggable({

            containment: '#timeline',
            axis: 'x',
            drag: function(event, ui) {

            var divs = $("#timeline div.timeline");
            for (var i=0, il=divs.length; i<il; i++) {
                var layer = '#layer'+i,
                gow = layer+"Go";
                SelectClosestKeyframes(this, event, ui, $(layer), $(gow));
            }
         }      
    });

Can I improve the for (var i=0, il=divs.length; i<il; i++)
Thanx

  • 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-15T22:50:30+00:00Added an answer on May 15, 2026 at 10:50 pm

    There’s no point in trying to optimize the loop mechanics given what you’re doing in the loop. First, I doubt you could get it significantly better anyway, and second because the cost of that loop code is dwarfed by the expense of all those jQuery calls.

    You start off by finding a bunch of <div> elements. You then iterate over that list, but your code never uses the “divs” array at all. Instead, it does 2 more jQuery lookups (albeit fairly cheap ones, as they’re based on element id) per iteration, plus whatever work is in that function.

    How did you come to the conclusion that the loop needs “optimization”? Is the page slow? If so, then I’d look inside that “SetClosestKeyframes” function and see what that does. Unless there are a couple million “div.timeline” elements, your problem is not the loop itself.

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

Sidebar

Related Questions

I have below Jquery with me. $(.load-fragment).each(function() { var $objThis = $(this); var fname
I have a jQuery function already to perform the task I need but is
I have a function which performs a foreach loop on an array from a
This is my current flow of JQuery: Object is created. Object has a function
I have a simple jQuery function as $('.button').click(function(){ $(#target).slideToggle().load('http://page'); }); By slideToggle behavior, every
Suppose I have performed an AJAX call with jQuery in the following fashion: key
I have this weird issue that jquery.load sometimes fails on chrome. I'm not gonna
I have some content that I am show/hiding using the Jquery toggle function. I
I have a timer every 20 seconds using setInterval, it uses jQuery's ajax function
I have written this code to benchmark jQuery vs DOM performance. The performance is

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.