Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.each running too slowly

Posted on 2013-01-06
1
Medium Priority
?
132 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 2000 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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

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 …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

688 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