Solved

.each running too slowly

Posted on 2013-01-06
1
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

734 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