Angelblade
asked on
Javascript childNodes problem
Hi I will try to explain my problem:
I have a function: getChild() that returns the childnodes of an element exept the child with nodetype == 3.
I have an other function: HasChange() that use getChild() to find the firstChild ( here in var div ) and the second child ( here in var input ) and return if the div.innerHTML and input.value are différent or not.
All works great but when i use the both function in my third function: test() a strange thing happened.
HasChange() return the value expected but I lost the content of editables[i] that becomes undefined.
So I get an error in the remove_control() function that have lost the argument editables[i].
If i run the function test2() all works great, but i find stupid to save editables[i] in the element var just to escape this strange behavior after the element is passed to HasChange();
Thanks for your help.
I have a function: getChild() that returns the childnodes of an element exept the child with nodetype == 3.
I have an other function: HasChange() that use getChild() to find the firstChild ( here in var div ) and the second child ( here in var input ) and return if the div.innerHTML and input.value are différent or not.
All works great but when i use the both function in my third function: test() a strange thing happened.
HasChange() return the value expected but I lost the content of editables[i] that becomes undefined.
So I get an error in the remove_control() function that have lost the argument editables[i].
If i run the function test2() all works great, but i find stupid to save editables[i] in the element var just to escape this strange behavior after the element is passed to HasChange();
Thanks for your help.
Object.prototype.getChild = function getChild(){
var array = this.childNodes; var Childs = Array(); var j=0;
for(i=0;i<array.length;i++){ if (array[i].nodeType != 3){ Childs[j] = array[i]; j++; } }
return Childs;
}
function HasChange(element){
var div = element.getChild()[0].getChild()[0];
var input = element.getChild()[0].getChild()[1];
return ( div.innerHTML == input.value ) ? false : true;
}
function test(){
for(i=0; i<editables.length; i++){
if ( !HasChange(editables[i]) ){
remove_control(editables[i]);
}
}
}
function test(){ var element = editables[i];
for(i=0; i<editables.length; i++){
if ( !HasChange(editables[i]) ){
remove_control(element);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No.
ASKER
But if I have to use the same way to programm for an other utility, any idea why I lost the element passed to HasChange() in this example?