T
Tim Streater
My app displays a table in a browser window. The user has the option to
display a different table by clicking a button. I effect this by
switching table bodies - I have an array containing pointers to a set of
tbodies.
Now, while this all works OK, if I wish to search for a row in such a
table body by id, I'm only using getElementById() on the tbody that
happens to be in the DOM just now. If I want to look for a row in
another tbody, I'm having to search for that by hand with a JavaScript
loop, which I assume is a lot slower than using getElementById.
To get round this, I'm thinking that if I can create another document, I
could append the tbody I want to search to that and then use
getElementById on the result. Something like:
mydocPtr = document.createElement("document");
mydocPtr.appendChild(tbodyPtr);
rowPtr = mydocPtr.getElementById(someId);
Can I create a document element in this way? Anything I should be wary
of?
display a different table by clicking a button. I effect this by
switching table bodies - I have an array containing pointers to a set of
tbodies.
Now, while this all works OK, if I wish to search for a row in such a
table body by id, I'm only using getElementById() on the tbody that
happens to be in the DOM just now. If I want to look for a row in
another tbody, I'm having to search for that by hand with a JavaScript
loop, which I assume is a lot slower than using getElementById.
To get round this, I'm thinking that if I can create another document, I
could append the tbody I want to search to that and then use
getElementById on the result. Something like:
mydocPtr = document.createElement("document");
mydocPtr.appendChild(tbodyPtr);
rowPtr = mydocPtr.getElementById(someId);
Can I create a document element in this way? Anything I should be wary
of?