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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:57:16+00:00 2026-06-13T07:57:16+00:00

I have 2000 rows of data as follows <div class=rr cf> <span>VLKN DR EXP</span>

  • 0

I have 2000 rows of data as follows

<div class="rr cf">
    <span>VLKN DR EXP</span>
    <span>01046</span>
    <span>VELANKANNI</span>
    <span>20:30</span>
    <span>DADAR</span>
    <span>10:00</span>
</div>

On a button click I am checking for text within them and updating the display of each row to block or none. The code that does this is

$('.rr').each(function(){
    this.style.display="block";
});

var nodes = $(".rr");
for(var i=0;i < nodes.length; i++) {
     // if data found
         nodes.get(i).style.display="block";
     // else
         nodes.get(i).style.display="none";
}

This seems to be possibly very slow. I get chrome alert box as to kill the page.

Any ideas? what optimization can I do here?

  • 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-06-13T07:57:17+00:00Added an answer on June 13, 2026 at 7:57 am

    Local Variables and Loops


    Another simple way to improve the performance of a loop is to
    decrement the iterator toward 0 rather than incrementing toward the
    total length. Making this simple change can result in savings of up to
    50% off the original execution time, depending on the complexity of
    each iteration.

    Taken from: http://oreilly.com/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html

    • Try saving the nodes.length as a local variable so that the loop doesn’t have to compute it each time.
    • Also, you can store nodes.get(i) into a local variable to save some time if you are accessing that data a lot.
    • If the order isn’t important, consider decrementing your for loop towards 0.
    • jQuery’s each() loop is a bit slower than looping through the set yourself as well. You can see here that there is a clear difference.

    Very simple example

    You’ll see that in my example, I’ve condensed the loop into a while loop:

    var nodes = $(".rr span");
    var i = nodes.length;
    
    while(i--){ 
      if(i%2 === 0){
        nodes.get(i).style.color = "blue";}
    }​
    

    Notice that the while loop decrements i through each iteration. This way when i = 0, the loop will exit, because while(0) evaluates to false.


    “Chunking” the Array


    The chunk() function is designed to process an array in small chunks
    (hence the name), and accepts three arguments: a “to do” list of
    items, the function to process each item, and an optional context
    variable for setting the value of this within the process() function.
    A timer is used to delay the processing of each item (100ms in this
    case, but feel free to alter for your specific use). Each time
    through, the first item in the array is removed and passed to the
    process() function
    . If there’s still items left to process, another
    timer is used to repeat the process.

    Have a look at Nick Zakas‘s chunk method defined here, if you need to run the loop in sections to reduce the chance of crashing the browser:

    function chunk(array, process, context){
        setTimeout(function(){
            var item = array.shift();
            process.call(context, item);
    
            if (array.length > 0){
                setTimeout(arguments.callee, 100);
            }
        }, 100);
    } 
    

    Using createDocumentFragment()


    Since the document fragment is in memory and not part of the main DOM
    tree, appending children to it does not cause page reflow (computation
    of element’s position and geometry). Consequently, using document
    fragments often results in better performance.

    DocumentFragment are supported in all browsers, even Internet Explorer
    6, so there is no reason to not use them.

    Reflow is the process by which the geometry of the layout engine’s
    formatting objects are computed.

    Since you are changing the display property of these elements iteratively, the page mush ‘repaint’ the window for each change. If you use createDocumentFragment and make all the changes there, then push those to the DOM, you drastically reduce the amount of repainting necessary.

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

Sidebar

Related Questions

SQL SERVER 2000: I have a table with test data (about 100000 rows), I
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
I have a SQL 2000 database with around 10 million rows and I need
I have a data frame with 72 columns and 409 rows which is called:
My scenario is as follows: I have a table of data (handful of fields,
I have the following data in a SQL Server 2000 table: Dates ----------------------- 2012-05-04
I have data in some text file which has let's say 10000 rows and
I am using SQL Server 2008 Enterprise. I have yearly customer data from 2000
I got like 2000 rows of data, when I do select statement I can
I have multiple .csv files with a large matrix, ~300 rows and 2000 cols.

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.