Hola
minkweb:
Prueba con esto:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<head>
<meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
<meta name="Author" content="derkeNuke" />
<title>Página nueva</title>
<style type="text/css">
</style>
</head>
<body>
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr id="unTR">
<td></td>
<td></td>
</tr>
<tr id="otroTR">
<td></td>
<td></td>
</tr>
</table>
<script type="text/javascript">
<!--
// Buscamos el elemento superior a elemento que tenga por tag tag. Hasta el body nada más.
function padre(elemento, tag) {
do {
elemento = elemento.parentNode;
} while( elemento.nodeType!==3 && elemento.tagName.toUpperCase()!==tag.toUpperCase() && elemento.tagName.toUpperCase()!=="BODY" );
return elemento;
}
// Devuelve la posición de un TR dentro de su tabla
function posicionTR(idTR) {
var tr = document.getElementById(idTR);
var suTabla = padre(tr, "TABLE");
var susTR = suTabla.getElementsByTagName("TR");
for(var i=0; i<susTR.length; i++) {
if( susTR[i] === tr )
return i;
}
return false;
}
window.onload = function() {
alert( posicionTR("unTR") );
alert( posicionTR("otroTR") );
}
// -->
</script>
</body>
</html>
Buscamos su tabla, recogemos sus TR, y luego vamos fila por fila hasta hallar cuál es el que buscabamos.
Un saludo