Re: [WSG] document.getElementById slow?

2007-10-06 Thread Andrew Ingram
liorean, You're probably right, I neglected to consider that browsers probably hash the possible results for getElementById whereas they probably don't assign all the DOM properties for every node when the page is loaded so this would have to be manually cached by the programmer. Regards, A

RE: [WSG] document.getElementById slow?

2007-10-06 Thread Kepler Gelotte
> When in doubt, test! All else is futile speculation: > Hi Nick, Thanks for the script. I suspected your results may be a bit skewed because: 1) The DOM structure was very small 2) There are different implementations of the JavaScri

Re: [WSG] document.getElementById slow?

2007-10-06 Thread liorean
On 05/10/2007, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi Simon, > > Direct access will always be faster, here's how the methods work: > > getElementById has to recurse through every child element (the approach of > the recursion may vary from browser-to-browser) until it finds an element >

Re: [WSG] document.getElementById slow?

2007-10-06 Thread Nick Fitzsimons
On 5 Oct 2007, at 13:28:32, Simon Cockayne wrote: So which is faster? document.forms.myform.elements.field1 or document.getElementById(field1) When in doubt, test! All else is futile speculation: (Script at

Re: [WSG] document.getElementById slow?

2007-10-05 Thread Matias Lespiau
Hi, Also consider that accessing the element directly also leads to less-maintainable code, as a change in the DOM (presentation) might requre you to change the javascript code ( behaviour ). In my humble opinion, you should use getElementById as the loss of performance is greatly compensated by m

Re: [WSG] document.getElementById slow?

2007-10-05 Thread Christian Snodgrass
As others have said before, direct access will be always be faster than the getElementById(), assuming that you are actually getting direct access (which I'm not 100% sure about). However, I would say the difference in the speed for most pages would be almost unnoticeable, probably only a coupl

Re: [WSG] document.getElementById slow?

2007-10-05 Thread andy
Hi Simon, Direct access will always be faster, here's how the methods work: getElementById has to recurse through every child element (the approach of the recursion may vary from browser-to-browser) until it finds an element that matches the id and then it breaks out of the loop and returns the e

RE: [WSG] document.getElementById slow?

2007-10-05 Thread Kepler Gelotte
> So which is faster? > > document.forms.myform.elements.field1 > > or > > document.getElementById(field1) Hi Simon, First of all thanks for breaking the Target thread ;-) I haven't looked at the code of the Rhino javascript engine, but what your friend says makes sense. The browser creates

[WSG] document.getElementById slow?

2007-10-05 Thread Simon Cockayne
Hi, http://developer.mozilla.org/en/docs/Using_Web_Standards_in_your_Web_Pages states: "The best and most supported practice for getting scriptable access to an element in an HTML page is to use document.getElementById(id). " A colleague of mine reckons such access will be much slower than acces