...

View Full Version : get this element placement within parent



BubikolRamios
11-11-2012, 01:29 PM
<table>
<td>
</td>
<td onclick = "somefunction (this);">
</td>
<td>
</td>
</table>


Is it possible that somefunction would return 1 (via parentNode.getelementsbytagname), as this is second td within table ?
No id's, no nothing on elements inside table.

DaveyErwin
11-11-2012, 02:09 PM
<script>
function somefunction(el){
var count=0;
var nodes=el.parentNode.getElementsByTagName(el.tagName);
while(nodes[count++])
if(nodes[count-1] === el)
alert(count-1);
};

</script>
<body>
<table> <td> </td> <td onclick = "somefunction (this);"> clickMe </td> <td> </td> </table>
</body>

BubikolRamios
11-11-2012, 04:03 PM
Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum