Solved

.each running too slowly

Posted on 2013-01-06
1
129 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting selected value of a dropdown with jquery 7 57
jQuery dialog box help 2 17
jQuery force form POST 7 51
Help with Javascript to round decimal points to 2 13 18
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)

828 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