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