tempo fa mi ero fatto questa funzione. La usavo sopratutto per trovarmi la riga da un qualunque elemento in essa contenuta. Vedi se la puoi adattare al tuo caso:
codice:
/*--------------------------------------------------------
dato un oggetto v, restituisce il primo contenitore
di tipo tag, o se stesso se è del tipo cercato
Se indico pure id, mi trova il primo contenitore o se stesso
di tipo tag e di dato id
--------------------------------------------------------*/
function getParentElement(v, tag, id)
{
if(v == undefined) return undefined;
if(v.tagName)
{
if(id == undefined)
{
if( v.tagName.toUpperCase( ) == tag.toUpperCase( ) ) return v;
}
else
{
if( v.id == id ) return v;
}
}
var w = v.parentNode;
if(w == undefined) return undefined;
if(w.tagName)
{
if(id == undefined)
{
if( v.parentNode.tagName.toUpperCase( ) == tag.toUpperCase( ) )
return v.parentNode;
else
return getParentElement(v.parentNode, tag);
}
else
{
if( v.id == id )
return v.parentNode;
else
return getParentElement(v.parentNode, tag, id);
}
}
else return undefined;
}
la richiamo così:
<tr><td><div onclick="getParentElement(this, 'tr')"...==> sto cercando la riga tr