Solved

.each running too slowly

Posted on 2013-01-06
1
127 Views
Last Modified: 2013-01-28
Ive built a simple function to look at each div, and then then height of each child div inside, get the maximum height, and then set the largest height to all of the child divs:-
                $(".clsTransactionRow").each( function () {
                  var maxHeight = 0;
                  $(this).find("div").each(function () { maxHeight = Math.max(maxHeight,$(this).height()); });
                  $(this).find("div").height(maxHeight);
                  });

Open in new window


It works fine, however I have 2796 divs that are .clsTransactionRow so the above code take 45 seconds to run, which is unacceptable.

Can anyone think of anyway to optimise the my code, or make it quicker?

Thank you
0
Comment
Question by:tonelm54
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38749032
Could you use a good size with CSS?
Else try this :
  $(".clsTransactionRow").each( function () {    
    var maxHeight = 0;
    var divs = this.getElementsByTagName("div");
    for(var d=0;d<divs.length;d++) {
      var h = $(divs[d]).height();
      if(h>maxHeight) {
        $(divs[d]).prev("div").height(h);
        maxHeight = h;
      }
    };
  });

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now