Interessante perchè non fa uso della ricorsione
L'ho modificato così:
codice:
//---------------------------------------------------
//restituisce true o false a seconda se elemento
//sia contenuto nel contenitore di id = searchId
//---------------------------------------------------
function checkIfParent(elemento, searchId)
{
var thisdiv = elemento;
if(thisdiv.getAttribute('id') == searchId)
{
alert(elemento.id + " è " + searchId);
return true;
}
while (thisdiv.parentNode.tagName != undefined)
{
if (thisdiv.parentNode.getAttribute('id') == searchId)
{
alert(elemento.id + " è contenuto in "+ searchId);
return true;
}
thisdiv = thisdiv.parentNode;
}
alert(elemento.id + " non è contenuto in " + searchId);
return false;
}