Speed Up document.getElementById()?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vunet.us@gmail.com

    Speed Up document.getElementById()?

    Hello,
    My AJAX application paints data into about 500 cells with unique ID
    every 10 seconds. I am using document.getEle mentById() to find the
    right cell. However, I have noticed that document.getEle mentById() in
    IE is freezing the browser for about 1 second unlike Firefox.
    Can anyone suggest any speed improvements for painting data into a
    large number of cells to speed up the process?

  • Derek

    #2
    Re: Speed Up document.getEle mentById()?

    Have you tried creating a javascript array of all of the cells as you
    create (or after you create: depending if they're dynamically created
    or not) the document elements? Then you can just reference the array's
    mapped ID instead of IE finding the document element every time. I
    don't know for sure if this would be faster, but it seems it would be.
    (slightly longer start-up, but faster once everything is loaded)

    For example, at the beginning:

    var arr = new Array(500);
    for (x in arr)
    {
    arr[x] = document.getEle mentById('cell' + x);
    }

    Then, throughout the rest of your document, simply use "arr[ID]" to
    point to the document element you are wanting to manipulate.

    On Apr 30, 9:36 am, vunet...@gmail. com wrote:
    Hello,
    My AJAX application paints data into about 500 cells with unique ID
    every 10 seconds. I am using document.getEle mentById() to find the
    right cell. However, I have noticed that document.getEle mentById() in
    IE is freezing the browser for about 1 second unlike Firefox.
    Can anyone suggest any speed improvements for painting data into a
    large number of cells to speed up the process?

    Comment

    • vunet.us@gmail.com

      #3
      Re: Speed Up document.getEle mentById()?

      On Apr 30, 10:15 am, Derek <derek.detwei.. .@gmail.comwrot e:
      Have you tried creating a javascript array of all of the cells as you
      create (or after you create: depending if they're dynamically created
      or not) the document elements? Then you can just reference the array's
      mapped ID instead of IE finding the document element every time. I
      don't know for sure if this would be faster, but it seems it would be.
      (slightly longer start-up, but faster once everything is loaded)
      >
      For example, at the beginning:
      >
      var arr = new Array(500);
      for (x in arr)
      {
      arr[x] = document.getEle mentById('cell' + x);
      >
      }
      >
      Then, throughout the rest of your document, simply use "arr[ID]" to
      point to the document element you are wanting to manipulate.
      >
      On Apr 30, 9:36 am, vunet...@gmail. com wrote:
      >
      Hello,
      My AJAX application paints data into about 500 cells with unique ID
      every 10 seconds. I am using document.getEle mentById() to find the
      right cell. However, I have noticed that document.getEle mentById() in
      IE is freezing the browser for about 1 second unlike Firefox.
      Can anyone suggest any speed improvements for painting data into a
      large number of cells to speed up the process?
      I will test your solution and post the results, thank you.

      Comment

      • vunet.us@gmail.com

        #4
        Re: Speed Up document.getEle mentById()?

        On Apr 30, 10:15 am, Derek <derek.detwei.. .@gmail.comwrot e:
        Have you tried creating a javascript array of all of the cells as you
        create (or after you create: depending if they're dynamically created
        or not) the document elements? Then you can just reference the array's
        mapped ID instead of IE finding the document element every time. I
        don't know for sure if this would be faster, but it seems it would be.
        (slightly longer start-up, but faster once everything is loaded)
        >
        For example, at the beginning:
        >
        var arr = new Array(500);
        for (x in arr)
        {
        arr[x] = document.getEle mentById('cell' + x);
        >
        }
        >
        Then, throughout the rest of your document, simply use "arr[ID]" to
        point to the document element you are wanting to manipulate.
        >
        On Apr 30, 9:36 am, vunet...@gmail. com wrote:
        >
        Hello,
        My AJAX application paints data into about 500 cells with unique ID
        every 10 seconds. I am using document.getEle mentById() to find the
        right cell. However, I have noticed that document.getEle mentById() in
        IE is freezing the browser for about 1 second unlike Firefox.
        Can anyone suggest any speed improvements for painting data into a
        large number of cells to speed up the process?
        It is a significant improvement when updating cells' content but I
        lose time when building this array. My cells are drawn dynamically.
        So, until I draw the whole table, I cannot create a reference array.
        However, when having this array, I repaint cell content much faster
        (by 80%) than if using document.getEle mentById().
        Thank you.
        PS: any suggestions for speed improvements to create a reference
        array? :)

        Comment

        • Derek

          #5
          Re: Speed Up document.getEle mentById()?

          If you are dynamically creating the cell elements, you can create the
          array at the same time you are creating the elements, instead of doing
          them all at once using the "for loop" and document.getEle mentById.
          Depending on how you are setting the ID's, it may be tricky at first,
          but you should be able to do something along the lines of:

          var arr = new Array(500);
          var yourTableContai ningCells =
          document.getEle mentById("yourT ablesID");

          /*
          * Automatically assign the reference when you dynamically create
          the element as follows.
          * Do this for each cell reference, whether it be inside a for loop
          or in some other function
          * you are currently using to construct your cells. Use "arr[x]"
          anywhere after this code to
          * point to the element having "cellx" as it's id. (ie. arr[4] is
          equivalent to id="cell4")
          */
          arr[thisElementsID] = document.create Element("div");
          arr[thisElementsID].setAttribute(" id", "cell" + thisElementsID) ;
          yourTableContai ningCells.inser tBefore(arr[thisElementsID],null);


          Hope this helps out! Let me know how things turn out.

          On Apr 30, 11:39 am, vunet...@gmail. com wrote:
          On Apr 30, 10:15 am, Derek <derek.detwei.. .@gmail.comwrot e:
          >
          >
          >
          Have you tried creating a javascript array of all of the cells as you
          create (or after you create: depending if they're dynamically created
          or not) the document elements? Then you can just reference the array's
          mapped ID instead of IE finding the document element every time. I
          don't know for sure if this would be faster, but it seems it would be.
          (slightly longer start-up, but faster once everything is loaded)
          >
          For example, at the beginning:
          >
          var arr = new Array(500);
          for (x in arr)
          {
          arr[x] = document.getEle mentById('cell' + x);
          >
          }
          >
          Then, throughout the rest of your document, simply use "arr[ID]" to
          point to the document element you are wanting to manipulate.
          >
          On Apr 30, 9:36 am, vunet...@gmail. com wrote:
          >
          Hello,
          My AJAX application paints data into about 500 cells with unique ID
          every 10 seconds. I am using document.getEle mentById() to find the
          right cell. However, I have noticed that document.getEle mentById() in
          IE is freezing the browser for about 1 second unlike Firefox.
          Can anyone suggest any speed improvements for painting data into a
          large number of cells to speed up the process?
          >
          It is a significant improvement when updating cells' content but I
          lose time when building this array. My cells are drawn dynamically.
          So, until I draw the whole table, I cannot create a reference array.
          However, when having this array, I repaint cell content much faster
          (by 80%) than if using document.getEle mentById().
          Thank you.
          PS: any suggestions for speed improvements to create a reference
          array? :)

          Comment

          • vunet.us@gmail.com

            #6
            Re: Speed Up document.getEle mentById()?

            On Apr 30, 12:03 pm, Derek <derek.detwei.. .@gmail.comwrot e:
            If you are dynamically creating the cell elements, you can create the
            array at the same time you are creating the elements, instead of doing
            them all at once using the "for loop" and document.getEle mentById.
            Depending on how you are setting the ID's, it may be tricky at first,
            but you should be able to do something along the lines of:
            >
            var arr = new Array(500);
            var yourTableContai ningCells =
            document.getEle mentById("yourT ablesID");
            >
            /*
            * Automatically assign the reference when you dynamically create
            the element as follows.
            * Do this for each cell reference, whether it be inside a for loop
            or in some other function
            * you are currently using to construct your cells. Use "arr[x]"
            anywhere after this code to
            * point to the element having "cellx" as it's id. (ie. arr[4] is
            equivalent to id="cell4")
            */
            arr[thisElementsID] = document.create Element("div");
            arr[thisElementsID].setAttribute(" id", "cell" + thisElementsID) ;
            yourTableContai ningCells.inser tBefore(arr[thisElementsID],null);
            >
            Hope this helps out! Let me know how things turn out.
            >
            On Apr 30, 11:39 am, vunet...@gmail. com wrote:
            >
            On Apr 30, 10:15 am, Derek <derek.detwei.. .@gmail.comwrot e:
            >
            Have you tried creating a javascript array of all of the cells as you
            create (or after you create: depending if they're dynamically created
            or not) the document elements? Then you can just reference the array's
            mapped ID instead of IE finding the document element every time. I
            don't know for sure if this would be faster, but it seems it would be.
            (slightly longer start-up, but faster once everything is loaded)
            >
            For example, at the beginning:
            >
            var arr = new Array(500);
            for (x in arr)
            {
            arr[x] = document.getEle mentById('cell' + x);
            >
            }
            >
            Then, throughout the rest of your document, simply use "arr[ID]" to
            point to the document element you are wanting to manipulate.
            >
            On Apr 30, 9:36 am, vunet...@gmail. com wrote:
            >
            Hello,
            My AJAX application paints data into about 500 cells with unique ID
            every 10 seconds. I am using document.getEle mentById() to find the
            right cell. However, I have noticed that document.getEle mentById() in
            IE is freezing the browser for about 1 second unlike Firefox.
            Can anyone suggest any speed improvements for painting data into a
            large number of cells to speed up the process?
            >
            It is a significant improvement when updating cells' content but I
            lose time when building this array. My cells are drawn dynamically.
            So, until I draw the whole table, I cannot create a reference array.
            However, when having this array, I repaint cell content much faster
            (by 80%) than if using document.getEle mentById().
            Thank you.
            PS: any suggestions for speed improvements to create a reference
            array? :)
            This perfectly makes sense. However, my table is created differently,
            as it is a much faster way (based on test cases) to draw big tables:

            var arrTable = new Array();
            arrTable.push(" <table><tr><td> ")
            arrTable.push(" qqq</td><td>")
            arrTable.push(" www</td><td>")
            arrTable.push(" </td></tr></table>")
            document.getEle mentById("conta iner").innerHTM L=arrTable.join (' ');

            which means I cannot get a reference until I draw the whole table,
            unless I go back to DOM method of creating a table as you mentioned
            above.

            Comment

            • Dr J R Stockton

              #7
              Re: Speed Up document.getEle mentById()?

              In comp.lang.javas cript message <1177940190.258 664.238930@o5g2 000hsb.goo
              glegroups.com>, Mon, 30 Apr 2007 06:36:30, vunet.us@gmail. com posted:
              >Hello,
              >My AJAX application paints data into about 500 cells with unique ID
              >every 10 seconds. I am using document.getEle mentById() to find the
              >right cell. However, I have noticed that document.getEle mentById() in
              >IE is freezing the browser for about 1 second unlike Firefox.
              >Can anyone suggest any speed improvements for painting data into a
              >large number of cells to speed up the process?
              Especially, but not only, if you are painting the cells in non-random
              order, ISTM that you should be reaching the cells by using the structure
              of the table that holds them. Get a link to the base of the data in the
              table, and index relatively to that.

              --
              (c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
              Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
              Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
              Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)

              Comment

              • Pete

                #8
                Re: Speed Up document.getEle mentById()?

                On May 1, 12:34 am, vunet...@gmail. com wrote:
                On Apr 30, 12:03 pm, Derek <derek.detwei.. .@gmail.comwrot e:
                >
                >
                >
                >
                >
                If you are dynamically creating the cell elements, you can create the
                array at the same time you are creating the elements, instead of doing
                them all at once using the "for loop" and document.getEle mentById.
                Depending on how you are setting the ID's, it may be tricky at first,
                but you should be able to do something along the lines of:
                >
                var arr = new Array(500);
                var yourTableContai ningCells =
                document.getEle mentById("yourT ablesID");
                >
                /*
                * Automatically assign the reference when you dynamically create
                the element as follows.
                * Do this for each cell reference, whether it be inside a for loop
                or in some other function
                * you are currently using to construct your cells. Use "arr[x]"
                anywhere after this code to
                * point to the element having "cellx" as it's id. (ie. arr[4] is
                equivalent to id="cell4")
                */
                arr[thisElementsID] = document.create Element("div");
                arr[thisElementsID].setAttribute(" id", "cell" + thisElementsID) ;
                yourTableContai ningCells.inser tBefore(arr[thisElementsID],null);
                >
                Hope this helps out! Let me know how things turn out.
                >
                On Apr 30, 11:39 am, vunet...@gmail. com wrote:
                >
                On Apr 30, 10:15 am, Derek <derek.detwei.. .@gmail.comwrot e:
                >
                Have you tried creating a javascript array of all of the cells as you
                create (or after you create: depending if they're dynamically created
                or not) the document elements? Then you can just reference the array's
                mapped ID instead of IE finding the document element every time. I
                don't know for sure if this would be faster, but it seems it would be.
                (slightly longer start-up, but faster once everything is loaded)
                >
                For example, at the beginning:
                >
                var arr = new Array(500);
                for (x in arr)
                {
                arr[x] = document.getEle mentById('cell' + x);
                >
                }
                >
                Then, throughout the rest of your document, simply use "arr[ID]" to
                point to the document element you are wanting to manipulate.
                >
                On Apr 30, 9:36 am, vunet...@gmail. com wrote:
                >
                Hello,
                My AJAX application paints data into about 500 cells with unique ID
                every 10 seconds. I am using document.getEle mentById() to find the
                right cell. However, I have noticed that document.getEle mentById() in
                IE is freezing the browser for about 1 second unlike Firefox.
                Can anyone suggest any speed improvements for painting data into a
                large number of cells to speed up the process?
                >
                It is a significant improvement when updating cells' content but I
                lose time when building this array. My cells are drawn dynamically.
                So, until I draw the whole table, I cannot create a reference array.
                However, when having this array, I repaint cell content much faster
                (by 80%) than if using document.getEle mentById().
                Thank you.
                PS: any suggestions for speed improvements to create a reference
                array? :)
                >
                This perfectly makes sense. However, my table is created differently,
                as it is a much faster way (based on test cases) to draw big tables:
                >
                var arrTable = new Array();
                arrTable.push(" <table><tr><td> ")
                arrTable.push(" qqq</td><td>")
                arrTable.push(" www</td><td>")
                arrTable.push(" </td></tr></table>")
                document.getEle mentById("conta iner").innerHTM L=arrTable.join (' ');
                >
                which means I cannot get a reference until I draw the whole table,
                unless I go back to DOM method of creating a table as you mentioned
                above.- Hide quoted text -
                >
                - Show quoted text -
                this code is pretty inefficient...

                is there a reason why you couldn't just do
                document.getEle mentById("conta iner").innerHTM L="<table><tr>< td>qqq</
                td><td>www</td><td>("</td></tr></table>";
                this will give a huge performance gain by eliminating array
                operations.

                why don't you post more code so we can help optimise.

                Comment

                • -Lost

                  #9
                  Re: Speed Up document.getEle mentById()?

                  Pete wrote:
                  On May 1, 12:34 am, vunet...@gmail. com wrote:
                  >On Apr 30, 12:03 pm, Derek <derek.detwei.. .@gmail.comwrot e:
                  >>
                  >>
                  >>
                  >>
                  >>
                  >>If you are dynamically creating the cell elements, you can create the
                  >>array at the same time you are creating the elements, instead of doing
                  >>them all at once using the "for loop" and document.getEle mentById.
                  >>Depending on how you are setting the ID's, it may be tricky at first,
                  >>but you should be able to do something along the lines of:
                  >>var arr = new Array(500);
                  >>var yourTableContai ningCells =
                  >>document.getE lementById("you rTablesID");
                  >>/*
                  >> * Automatically assign the reference when you dynamically create
                  >>the element as follows.
                  >> * Do this for each cell reference, whether it be inside a for loop
                  >>or in some other function
                  >> * you are currently using to construct your cells. Use "arr[x]"
                  >>anywhere after this code to
                  >> * point to the element having "cellx" as it's id. (ie. arr[4] is
                  >>equivalent to id="cell4")
                  >> */
                  >>arr[thisElementsID] = document.create Element("div");
                  >>arr[thisElementsID].setAttribute(" id", "cell" + thisElementsID) ;
                  >>yourTableCont ainingCells.ins ertBefore(arr[thisElementsID],null);
                  >>Hope this helps out! Let me know how things turn out.
                  >>On Apr 30, 11:39 am, vunet...@gmail. com wrote:
                  >>>On Apr 30, 10:15 am, Derek <derek.detwei.. .@gmail.comwrot e:
                  >>>>Have you tried creating a javascript array of all of the cells as you
                  >>>>create (or after you create: depending if they're dynamically created
                  >>>>or not) the document elements? Then you can just reference the array's
                  >>>>mapped ID instead of IE finding the document element every time. I
                  >>>>don't know for sure if this would be faster, but it seems it would be.
                  >>>>(slightly longer start-up, but faster once everything is loaded)
                  >>>>For example, at the beginning:
                  >>>>var arr = new Array(500);
                  >>>>for (x in arr)
                  >>>>{
                  >>>> arr[x] = document.getEle mentById('cell' + x);
                  >>>>}
                  >>>>Then, throughout the rest of your document, simply use "arr[ID]" to
                  >>>>point to the document element you are wanting to manipulate.
                  >>>>On Apr 30, 9:36 am, vunet...@gmail. com wrote:
                  >>>>>Hello,
                  >>>>>My AJAX application paints data into about 500 cells with unique ID
                  >>>>>every 10 seconds. I am using document.getEle mentById() to find the
                  >>>>>right cell. However, I have noticed that document.getEle mentById() in
                  >>>>>IE is freezing the browser for about 1 second unlike Firefox.
                  >>>>>Can anyone suggest any speed improvements for painting data into a
                  >>>>>large number of cells to speed up the process?
                  >>>It is a significant improvement when updating cells' content but I
                  >>>lose time when building this array. My cells are drawn dynamically.
                  >>>So, until I draw the whole table, I cannot create a reference array.
                  >>>However, when having this array, I repaint cell content much faster
                  >>>(by 80%) than if using document.getEle mentById().
                  >>>Thank you.
                  >>>PS: any suggestions for speed improvements to create a reference
                  >>>array? :)
                  >This perfectly makes sense. However, my table is created differently,
                  >as it is a much faster way (based on test cases) to draw big tables:
                  >>
                  >var arrTable = new Array();
                  >arrTable.push( "<table><tr><td >")
                  >arrTable.push( "qqq</td><td>")
                  >arrTable.push( "www</td><td>")
                  >arrTable.push( "</td></tr></table>")
                  >document.getEl ementById("cont ainer").innerHT ML=arrTable.joi n(' ');
                  >>
                  >which means I cannot get a reference until I draw the whole table,
                  >unless I go back to DOM method of creating a table as you mentioned
                  >above.- Hide quoted text -
                  >>
                  >- Show quoted text -
                  >
                  this code is pretty inefficient...
                  >
                  is there a reason why you couldn't just do
                  document.getEle mentById("conta iner").innerHTM L="<table><tr>< td>qqq</
                  td><td>www</td><td>("</td></tr></table>";
                  this will give a huge performance gain by eliminating array
                  operations.
                  >
                  why don't you post more code so we can help optimise.
                  I'd like to see proof of innerHTML being faster than array operations.
                  I personally don't believe it.

                  Especially in the case of generating a huge dynamic table.

                  --
                  -Lost
                  Remove the extra words to reply by e-mail. Don't e-mail me. I am
                  kidding. No I am not.

                  Comment

                  • Pete

                    #10
                    Re: Speed Up document.getEle mentById()?

                    I'd like to see proof of innerHTML being faster than array operations.
                    I personally don't believe it.
                    >
                    Especially in the case of generating a huge dynamic table.
                    >
                    ..var arrTable = new Array();
                    arrTable.push(" <table><tr><td> ")
                    arrTable.push(" qqq</td><td>")
                    arrTable.push(" www</td><td>")
                    arrTable.push(" </td></tr></table>")
                    document.getEle mentById("conta iner").innerHTM L=arrTable.join (' ');

                    has become


                    document.getEle mentById("conta iner").innerHTM L="<table><tr>< td>qqq</
                    td><td>www</td><td>("</td></tr></table>";


                    You don't see how the new code is faster? I just did a speed test and
                    the new code is 7 times faster.




                    Comment

                    • Pete

                      #11
                      Re: Speed Up document.getEle mentById()?

                      On May 1, 1:47 pm, Pete <peter.gal...@g mail.comwrote:
                      I'd like to see proof of innerHTML being faster than array operations.
                      I personally don't believe it.
                      >
                      Especially in the case of generating a huge dynamic table.
                      >
                      .var arrTable = new Array();
                      arrTable.push(" <table><tr><td> ")
                      arrTable.push(" qqq</td><td>")
                      arrTable.push(" www</td><td>")
                      arrTable.push(" </td></tr></table>")
                      document.getEle mentById("conta iner").innerHTM L=arrTable.join (' ');
                      >
                      has become
                      >
                      document.getEle mentById("conta iner").innerHTM L="<table><tr>< td>qqq</
                      td><td>www</td><td>("</td></tr></table>";
                      >
                      You don't see how the new code is faster? I just did a speed test and
                      the new code is 7 times faster.
                      By the way, arr.push is much slower than accessing the array directly.

                      Comment

                      • -Lost

                        #12
                        Re: Speed Up document.getEle mentById()?

                        Pete wrote:
                        On May 1, 1:47 pm, Pete <peter.gal...@g mail.comwrote:
                        >>I'd like to see proof of innerHTML being faster than array operations.
                        >>I personally don't believe it.
                        >>Especially in the case of generating a huge dynamic table.
                        >.var arrTable = new Array();
                        >arrTable.push( "<table><tr><td >")
                        >arrTable.push( "qqq</td><td>")
                        >arrTable.push( "www</td><td>")
                        >arrTable.push( "</td></tr></table>")
                        >document.getEl ementById("cont ainer").innerHT ML=arrTable.joi n(' ');
                        >>
                        >has become
                        >>
                        >document.getEl ementById("cont ainer").innerHT ML="<table><tr> <td>qqq</
                        >td><td>www</td><td>("</td></tr></table>";
                        >>
                        >You don't see how the new code is faster? I just did a speed test and
                        >the new code is 7 times faster.
                        Nope, sure don't.

                        By what means do you validate that?

                        Also, I think you missed "Especially in the case of generating a huge
                        dynamic table."
                        By the way, arr.push is much slower than accessing the array directly.
                        By what means do you validate that claim?

                        --
                        -Lost
                        Remove the extra words to reply by e-mail. Don't e-mail me. I am
                        kidding. No I am not.

                        Comment

                        • Pete

                          #13
                          Re: Speed Up document.getEle mentById()?

                          By what means do you validate that claim?
                          here is a timer object

                          function Timer() {
                          this.times = [];

                          this.record = function() {
                          this.times.push (new Date().getTime( ));
                          };

                          this.ticks = function() {
                          return (this.times.len gth 1 ? this.times.pop( ) -
                          this.times.pop( ) : 0);
                          };
                          };

                          call timer.record() to start the timer and then call it again to end
                          the timer.
                          then call timer.ticks() to get the time elapsed.

                          Wrap your code in a for loop and run it a few thousand times. do this
                          for code snippet 1 and then for code snippet 2. Pretty handy when
                          looking at code efficiency, or inefficiency in this case.


                          Comment

                          • vunet.us@gmail.com

                            #14
                            Re: Speed Up document.getEle mentById()?

                            is there a reason why you couldn't just do
                            document.getEle mentById("conta iner").innerHTM L="<table><tr>< td>qqq</
                            td><td>www</td><td>("</td></tr></table>";
                            The table is much bigger than just that: imagine 50 rows and 10
                            columns...


                            Comment

                            • vunet.us@gmail.com

                              #15
                              Re: Speed Up document.getEle mentById()?

                              On May 1, 12:39 am, -Lost <maventheextraw o...@techie.com wrote:
                              Pete wrote:
                              On May 1, 12:34 am, vunet...@gmail. com wrote:
                              On Apr 30, 12:03 pm, Derek <derek.detwei.. .@gmail.comwrot e:
                              >
                              >If you are dynamically creating the cell elements, you can create the
                              >array at the same time you are creating the elements, instead of doing
                              >them all at once using the "for loop" and document.getEle mentById.
                              >Depending on how you are setting the ID's, it may be tricky at first,
                              >but you should be able to do something along the lines of:
                              >var arr = new Array(500);
                              >var yourTableContai ningCells =
                              >document.getEl ementById("your TablesID");
                              >/*
                              > * Automatically assign the reference when you dynamically create
                              >the element as follows.
                              > * Do this for each cell reference, whether it be inside a for loop
                              >or in some other function
                              > * you are currently using to construct your cells. Use "arr[x]"
                              >anywhere after this code to
                              > * point to the element having "cellx" as it's id. (ie. arr[4] is
                              >equivalent to id="cell4")
                              > */
                              >arr[thisElementsID] = document.create Element("div");
                              >arr[thisElementsID].setAttribute(" id", "cell" + thisElementsID) ;
                              >yourTableConta iningCells.inse rtBefore(arr[thisElementsID],null);
                              >Hope this helps out! Let me know how things turn out.
                              >On Apr 30, 11:39 am, vunet...@gmail. com wrote:
                              >>On Apr 30, 10:15 am, Derek <derek.detwei.. .@gmail.comwrot e:
                              >>>Have you tried creating a javascript array of all of the cells as you
                              >>>create (or after you create: depending if they're dynamically created
                              >>>or not) the document elements? Then you can just reference the array's
                              >>>mapped ID instead of IE finding the document element every time. I
                              >>>don't know for sure if this would be faster, but it seems it would be.
                              >>>(slightly longer start-up, but faster once everything is loaded)
                              >>>For example, at the beginning:
                              >>>var arr = new Array(500);
                              >>>for (x in arr)
                              >>>{
                              >>> arr[x] = document.getEle mentById('cell' + x);
                              >>>}
                              >>>Then, throughout the rest of your document, simply use "arr[ID]" to
                              >>>point to the document element you are wanting to manipulate.
                              >>>On Apr 30, 9:36 am, vunet...@gmail. com wrote:
                              >>>>Hello,
                              >>>>My AJAX application paints data into about 500 cells with unique ID
                              >>>>every 10 seconds. I am using document.getEle mentById() to find the
                              >>>>right cell. However, I have noticed that document.getEle mentById() in
                              >>>>IE is freezing the browser for about 1 second unlike Firefox.
                              >>>>Can anyone suggest any speed improvements for painting data into a
                              >>>>large number of cells to speed up the process?
                              >>It is a significant improvement when updating cells' content but I
                              >>lose time when building this array. My cells are drawn dynamically.
                              >>So, until I draw the whole table, I cannot create a reference array.
                              >>However, when having this array, I repaint cell content much faster
                              >>(by 80%) than if using document.getEle mentById().
                              >>Thank you.
                              >>PS: any suggestions for speed improvements to create a reference
                              >>array? :)
                              This perfectly makes sense. However, my table is created differently,
                              as it is a much faster way (based on test cases) to draw big tables:
                              >
                              var arrTable = new Array();
                              arrTable.push(" <table><tr><td> ")
                              arrTable.push(" qqq</td><td>")
                              arrTable.push(" www</td><td>")
                              arrTable.push(" </td></tr></table>")
                              document.getEle mentById("conta iner").innerHTM L=arrTable.join (' ');
                              >
                              which means I cannot get a reference until I draw the whole table,
                              unless I go back to DOM method of creating a table as you mentioned
                              above.- Hide quoted text -
                              >
                              - Show quoted text -
                              >
                              this code is pretty inefficient...
                              >
                              is there a reason why you couldn't just do
                              document.getEle mentById("conta iner").innerHTM L="<table><tr>< td>qqq</
                              td><td>www</td><td>("</td></tr></table>";
                              this will give a huge performance gain by eliminating array
                              operations.
                              >
                              why don't you post more code so we can help optimise.
                              >
                              I'd like to see proof of innerHTML being faster than array operations.
                              I personally don't believe it.
                              >
                              Especially in the case of generating a huge dynamic table.
                              >
                              --
                              -Lost
                              Remove the extra words to reply by e-mail. Don't e-mail me. I am
                              kidding. No I am not.
                              I found some test cases in some books and online, plus tested myself.

                              Comment

                              Working...