T
Tim
Hey, so I have heard that it is better to use innerHTML to remove
nodes as opposed to removeChild but only in IE because of a problem
with circular references. Code I found in Ext supports this:
removeNode : isIE ? function(){
var d;
return function(n){
if(n && n.tagName != 'BODY'){
d = d || document.createElement('div');
d.appendChild(n);
d.innerHTML = '';
}
}
}() : function(n){
if(n && n.parentNode && n.tagName != 'BODY'){
n.parentNode.removeChild(n);
}
},
I also found some code which I currently use (I think from Douglas
Crockford) which is suppose to break the circular references:
function purge(d) {
var a = d.attributes, i, l, n;
if (a) {
l = a.length;
for (i = 0; i < l; i += 1) {
n = a.name;
if (typeof d[n] === 'function') {
d[n] = null;
}
}
}
a = d.childNodes;
if (a) {
l = a.length;
for (i = 0; i < l; i += 1) {
purge(d.childNodes);
}
}
}
Now I know the first one uses browser sniffing so thats no good, but
my real question is what solves the problem best?
Any suggestions?
Thanks
nodes as opposed to removeChild but only in IE because of a problem
with circular references. Code I found in Ext supports this:
removeNode : isIE ? function(){
var d;
return function(n){
if(n && n.tagName != 'BODY'){
d = d || document.createElement('div');
d.appendChild(n);
d.innerHTML = '';
}
}
}() : function(n){
if(n && n.parentNode && n.tagName != 'BODY'){
n.parentNode.removeChild(n);
}
},
I also found some code which I currently use (I think from Douglas
Crockford) which is suppose to break the circular references:
function purge(d) {
var a = d.attributes, i, l, n;
if (a) {
l = a.length;
for (i = 0; i < l; i += 1) {
n = a.name;
if (typeof d[n] === 'function') {
d[n] = null;
}
}
}
a = d.childNodes;
if (a) {
l = a.length;
for (i = 0; i < l; i += 1) {
purge(d.childNodes);
}
}
}
Now I know the first one uses browser sniffing so thats no good, but
my real question is what solves the problem best?
Any suggestions?
Thanks