I am making a XML-driven homepage. A menu structure is generated and when clicking on an menu element the content on the page is changed. When clicking on a level x element, its child is presented in a list in the main div. This is done by a function, changePage(id), that takes an id as argument to find correct XML-node to get the information.
I want this list elements to be links and when clicked on they should call changePage-function. This is used to step down in the tree.
var root = loadXML(aXML.xml);
function changePage(id){
var current_node = root; // <-- here I get error when clicking on the a-element.
... // creating list
var aElement = document.createElement('a');
aElement.onclick = new Function("changePage('" + index + "')");
}
When I click on my menu item everything works but when I click on the generated list-element I get an error that “current_node is not defined”. It seemse that root-variable cant be found when clicking on child.
What is wrong and what can i do to solve this?
Hi from what you have there you are killing the browser with new Functions ( overwriteing the old one )
Instead of:
you could use:
“arguments” is a keyword in js and contains an object with all the parameters passed to the function ( i.e. arguments[0] ) and also contains “callee” (the function itself) and “caller” (the function from which is called ). The second one (caller) is not cross-browser.
Best regards,