Script Problems (Speed & Compatibility)

A

Adelson Anton

Greetings fellow coders. Please check this page for a code which
rearranges chess cells:
http://s95005072.onlinehome.us/blog/Chess/chess.htm

There are 2 problems:
1. It takes quite a bit for the function to run each time. I don't know
how to speed it up further.
2. The function runs twice on mozilla browsers for some reason.

Any help is greatly appreciated. And hold your flames, this is my first
usable JS script.
 
A

Adelson Anton

An idea just came to me. Maybe problem #2 is because after every time I
click on the link, the onload event is fired. If I'm right, how do I
avoid it?
 
M

Mike

Not sure what you mean by slow. Seemed to work really fast with IE 6.0.

Anyway in general string concatenation can be slow and before IE 6.0 setting
the innerHTML property was pretty slow and I think is still slow for Mozilla
compared to using the DOM methods. But I may be out of date with this.

First I would recommend altering the code to use the DOM methods for element
creatation rather than using innerHTML. But if you want to use innerHTML the
faster way to perform string concatenation is to add the strings to an Array
and then perform an Array.join();

so

[snip]

var content = new String; // stores the table for output

content = "<table border='0' width='432' height='432' cellspacing='0'
cellpadding='0'>";
// first border row
content += "<tr height='9'>";

[/snip]

would become

var content = new Array();

content.push("<table border='0' width='432' height='432' cellspacing='0'
cellpadding='0'>");
// first border row
content.push("<tr height='9'>");
..
..
..
showContentObj.innerHTML=content.join();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top