Yes, I did mean position as in row, column.

In fact the code I had was fine, except for one thing:  in the alert,
I was trying to use the event itself (e) rather than the target (t).
(I didn't understand the (e && ...) code.)

Changing to "alert(t.cellIndex  + ', ' + t.parentNode.rowIndex)" works
fine in FF and IE both.

Your suggestion started me on the right track, and
http://www.quirksmode.org/js/events_properties.html
took me the rest of the way.

Thanks,
Matt


On 6/19/07, Scott Sauyet <[EMAIL PROTECTED]> wrote:
>
> Matt Conrad wrote:
> > I'm trying to find the cleanest way to get the position (x, y) of a
> > table cell that is clicked.  I'll eventually post the coordinates back
> > to the server.
>
> By (x, y) you mean (row, column) right, not pixel measurements?  That's
> what the code seemed to attempt.
>
> Without a live example, I'm going to be simply guessing, but, hey,
> that's never bothered me before!  :-)
>
> > function handleClick(e)
> > {
> >   var t;
> >   if (e && ((t = e.target) || (t = e.srcElement)))
> >   {
> >     alert(e.target.cellIndex + ', ' + e.target.parentNode.rowIndex);
> >   }
> > }
>
> I'm guessing that the target in IE is not the TD you are on.  Perhaps
> it's a text node inside your TD.
>
> You might add something like this (untested):
>
>      if (!$(t).is("td")) {
>          t = $(t).parents("td")[0];
>      }
>
> That should, I believe, give you the first TD containing the cell you
> are interested in.
>
> You can see more about parents at
>
>      http://docs.jquery.com/DOM/Traversing#parents.28_expr_.29
>
>
> Good luck,
>
>    -- Scott
>
>

Reply via email to