I’m not a javascript programmer by any means, but this has been annoying me for the longest while,
is there a better way to write these two seperate functions.
As in a single function?
function showAll()
{
var collection = getElementsByClassName("dealHolder");
for (var x = 0; x < collection.length; x++)
{
setParentTrue(collection[x].parentNode);
}
}
function setParentTrue(obj) {
if (obj.id != "deal")
{
obj.id = "true";
setParentTrue(obj.parentNode);
}
else
{
obj.style.display = 'block';
}
}
Can I declare a function within another and recursively call it? any time I need to recurse I always seem to be creating a separate function specifically for it
Cheers for the advice
1 Answer