CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   get this element placement within parent (http://www.codingforums.com/showthread.php?t=281886)

BubikolRamios 11-11-2012 12:29 PM

get this element placement within parent
 
Code:

<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 01:09 PM

Code:


<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 03:03 PM

Thanks.


All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.