Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2006, 08:51 PM   PM User | #1
DeChainsaw
New to the CF scene

 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
DeChainsaw is an unknown quantity at this point
Internet Explorer Optimizing a Script for Organizing Unordered Lists

Hello,

I’ve been using (and trying to learn) JavaScript for a while. I’ve been trying to push farther and farther without help, but finally hit an issue I’m still far too green to deal with. So, I started looking around for a forum where I can talk to people who know JavaScript, and came across this one.

It seems like I’m the only person within a 100 mile radius who even knows what JavaScript is. So, hopefully I’ll be able to pick some skill up from you guys. Anyway, enough rambling... ^_^;

I have a script that takes about 3 seconds to initialize in Firefox. However, in Internet Explorer it takes about 15 seconds to run. The script goes through a list of what is probably several hundred items and attempts to reorganize them. I originally found it on A List Apart (Original Article).

After reading a bit on optimization (some of which flew way over my head), timing some code, and commenting some parts out, I seem to have found a line that increases the run time by about 10 seconds.

Here is a portion of the code.

Code:
lis=document.getElementById('finder').getElementsByTagName('li');
var n = lis.length;
for(var i=0; i<n; i++){

	// if the li containing the link has no nested list, skip this one
	if(!lis[i].getElementsByTagName('ul')[0])
	{
		continue;
	}
	var newa=document.createElement('a');
	newa.href='#';
	if(lis[i].className == 'showimg')
	{
		var newimg=document.createElement('img');
		newimg.src='resources/images/logo/' + lis[i].firstChild.nodeValue + '.jpg';
		newimg.alt= lis[i].firstChild.nodeValue;
		newimg.title= lis[i].firstChild.nodeValue;
		newa.appendChild(newimg);
	}

	newa.appendChild(document.createTextNode(lis[i].firstChild.nodeValue));//

	// The offending line...
	lis[i].replaceChild(newa,lis[i].firstChild);

// ...The script goes on from here
This script is an attempt at crating something like the OSX finder in column mode. The article on ala most likely explains what I’m trying to achieve far better then I ever could. If I recall, the only real changes I’ve made is the addition of className check and the extra junk being thrown into the A element.

The last line, “lis[i].replaceChild(newa,lis[i].firstChild);” is the one causing the most trouble. Unfortunately, I have no idea how I can optimize it. Any help, hints, or ticks would be greatly appreciated.

Please let me know if other information would be helpful. Thanks in advance for any responses! :D
DeChainsaw is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:35 PM.


Advertisement
Log in to turn off these ads.