469,279 Members | 2,261 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,279 developers. It's quick & easy.

JavaScript Memory Leakage Problem With SetAttribute

Hello All,

I have made an AJAX call and bringing back some data from the server and then That data would be converted to XML through javascript. Now i am creating various elements like TABLE, TR, TD, Anchor to render that data using createElement method. and also i have to set some Usual and custom attributes to those elements and then render it on page.
Now my problem is when i use element.setAttribute(name, value) in a loop then after rendering 80 rows my IE shows alert that "This script is taking to long to run and should be aborted YES|NO " this kind of warning so can anybody help me where i am wrong and what kind of optimization can be done or there is any alternative for that.

This function is used for setting the attributes.

Expand|Select|Wrap|Line Numbers
  1.     function processTagAttributes(target, attributes){
  2.             if(attributes != null){
  3.                 for (i = 0; i<attributes.length; i++){
  4.                     var splited = attributes[i].split("|");
  5.                     if( splited[0] == 'style'){
  6.                             target.style.cssText =  splited[1];
  7.                     }
  8.                     else if( splited[0] == 'class'){
  9.                         target.className =  splited[1];
  10.                     }
  11.                     else{
  12.                         target.setAttribute( splited[0],  splited[1], 0);
  13.                     }
  14.                 }
  15.                 attributes = null;
  16.             }
  17.     }
EG attributes:--> var attributes = new Array("height|100", "width|100", "align|center");
Oct 31 '07 #1
5 1828
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Why are you using three arguments for setAttribute? See link.
Oct 31 '07 #2
The third attribute is optional for overriding the case sensitivity of the attribute name


Defination provided by W3C Level 1

setAttribute Method

--------------------------------------------------------------------------------

Sets the value of the specified attribute.

Syntax

object.setAttribute(sName, vValue [, iFlags])
Parameters

sName Required. String that specifies the name of the attribute.
vValue Required. Variant that specifies the string, number, or Boolean to assign to the attribute.
iFlags Optional. Integer that specifies one the following flags: 0 When the attribute is set, it overwrites any attributes with the same name, regardless of their case.
1 Default. The case of the attribute that you set is respected when it is set on the object.
Oct 31 '07 #3
acoder
16,027 Expert Mod 8TB
That is not part of the standard. See W3C DOM Level 2 setAttribute(). Where are you quoting from?
Oct 31 '07 #4
First of all i must tell u that my development module is browser IE specific and the second thing is that i have written Level One See the link
http://msdn2.microsoft.com/en-us/library/ms536739.aspx
Oct 31 '07 #5
acoder
16,027 Expert Mod 8TB
First of all i must tell u that my development module is browser IE specific and the second thing is that i have written Level One See the link
http://msdn2.microsoft.com/en-us/library/ms536739.aspx
It's not part of level 1 either, but since your user environment is restricted to IE, it's not too much of a problem. Just be mindful not to use it on public projects.

Coming to your problem, how long does it take to render 80 rows? How many attributes are there and show the code you're using to call this function for the table rows/cells.
Oct 31 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by relaxedrob | last post: by
10 posts views Thread by s.subbarayan | last post: by
18 posts views Thread by Ramasubbu Ramasubramanian XR (AS/EAB) | last post: by
8 posts views Thread by =?Utf-8?B?QW1yaXQgS29obGk=?= | last post: by
14 posts views Thread by madhawi | last post: by
2 posts views Thread by sorobor | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.