[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Javascript childNodes problem

Posted on 2009-07-02
3
Medium Priority
?
1,148 Views
Last Modified: 2012-05-07
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.
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); 
		}
	}
}

Open in new window

0
Comment
Question by:Angelblade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 750 total points
ID: 24762540
0
 

Author Comment

by:Angelblade
ID: 24764223
Okay, for sure this is a better way to do :)

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?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24764521
No.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question