Hi all, ive been racking my brains for hours trying to figure out why this little peice of code is failing to work! Hopefully you can be of some help.
How it should work:
Gets a parent node, grabs the children and then adds an onclick function to each, when the onmousedown function is initiated it goes through all the childnodes and changes the classnames back to a default, then changes the classname of the clicked childnode to highlight.
Problem:
The classnames are not set back to the default! seems the 'replace' is not working for some reason. The 'alert' test shows me the classname with 'click' appended to the end of the last despite the fact the 'replace' function should remove them all!
The code:-
function hoverEffects(node)
{
var node = document.getElementById(node);
for ( var x = 0; x < node.childNodes.length; x++ ){
node.childNodes[x].onmousedown = function(){
for ( var i = 0; i < node.childNodes.length; i++ ) {
var leaf = node.childNodes;
if ( !leaf ) alert("No Leaf");
if ( leaf.style ){
leaf.className.replace(/click/gi, "");
alert("TESTING: The class name is "+leaf.className);
}
}
this.className += "click";
}
}
}
Im totally mythed! Any help would be much appreciated, probably something terribly simple
How it should work:
Gets a parent node, grabs the children and then adds an onclick function to each, when the onmousedown function is initiated it goes through all the childnodes and changes the classnames back to a default, then changes the classname of the clicked childnode to highlight.
Problem:
The classnames are not set back to the default! seems the 'replace' is not working for some reason. The 'alert' test shows me the classname with 'click' appended to the end of the last despite the fact the 'replace' function should remove them all!
The code:-
function hoverEffects(node)
{
var node = document.getElementById(node);
for ( var x = 0; x < node.childNodes.length; x++ ){
node.childNodes[x].onmousedown = function(){
for ( var i = 0; i < node.childNodes.length; i++ ) {
var leaf = node.childNodes;
if ( !leaf ) alert("No Leaf");
if ( leaf.style ){
leaf.className.replace(/click/gi, "");
alert("TESTING: The class name is "+leaf.className);
}
}
this.className += "click";
}
}
}
Im totally mythed! Any help would be much appreciated, probably something terribly simple