RE: which is faster target.getElementsByTagName or target.firstChild / nextSibling
"Moran Ben-David" <[email protected]> Thu, 6 Apr 2006 20:13:48 -0400
| Newsgroups | gmane.comp.web.dom.wdf |
|---|---|
| Message-ID | <002501c659d8$24b55770$6401a8c0@short> |
You could try calling these functions in a loop 1000 times and measuring the time to execute the loop. This way you have a test that can you can run on each browser you intend to support. moran > -----Original Message----- > From: [email protected] [mailto:[email protected]] On Behalf > Of becs027 > Sent: Thursday, April 06, 2006 7:44 PM > To: [email protected] > Subject: [wdf-dom] which is faster target.getElementsByTagName or > target.firstChild / nextSibling > > Hi all, > > I'm doing an onload script to add rollover behaviour to list items > (dropdown menu style) for IE, and want to check which of two ways is > faster. > > ------------------------------------------------ > > Option 1 - add the behaviour using target.getElementsByTagName: > > if (document.getElementById('navigation')) { > var target = document.getElementById('navigation'); > var targetbuttons = target.getElementsByTagName('li'); > > for (var i = 0; i < targetbuttons.length; i++) { > targetbuttons[i].onmouseover = rollover; > targetbuttons[i].onmouseout = rolloff; > } > } > > ------------------------------------------------ > > Option 2 - add the behaviour with a while loop using firstChild, > nextSibling: > > if (document.getElementById('navigation')) { > var target = document.getElementById('navigation'); > var targetbutton = target.firstChild; > > while (targetbutton) { > targetbutton.onmouseover = rollover; > targetbutton.onmouseout = rolloff; > targetbutton = targetbutton.nextSibling; > } > } > > ------------------------------------------------ > > Thanks :) > Rebecca > > > > > > Unsubscribe > [email protected] > > List info > http://www.quirksmode.org/dom/list.html > Yahoo! Groups Links > > > > > Unsubscribe [email protected] List info http://www.quirksmode.org/dom/list.html Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/wdf-dom/ <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/