Finding td element position in table row
<p>How would I go about finding a td element's position in a table row? I have seen this code suggested, but is there a way to do this with having each td tag contain an onclick event? </p>

<pre><code>&lt;table&gt;
  &lt;tr&gt;
    &lt;td onclick="myFunction(this)"&gt;Click to show cellIndex&lt;/td&gt;
    &lt;td onclick="myFunction(this)"&gt;Click to show cellIndex&lt;/td&gt;
    &lt;td onclick="myFunction(this)"&gt;Click to show cellIndex&lt;/td&gt;
    &lt;td onclick="myFunction(this)"&gt;Click to show cellIndex&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;script&gt;
 function myFunction(x) {
   alert("Cell index is: " + x.cellIndex);
}
&lt;/script&gt;
</code></pre>

<p>I have a grid of images and I am trying to see which images in the grid have been clicked. I tried this:</p>

<pre><code>$('td img').on('click', function(x){
   console.log("Cell index is: " + x.cellIndex); 
});
</code></pre>

<p>But it just logs <code>undefined</code></p>