Find left position of table cell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ted

    #1

    Find left position of table cell

    Hi,

    Was wondering if it's possible to find the left position of a table cell if
    the cell is created dynamically.

    I have a table with a single cell. When a button is clicked, I'd like to add
    another cell to it, give the cell a class style and then find the cell's
    left position.

    Right now I'm using doing this:

    cell = document.create Element("td");
    cell.appendChil d("sometext") ;
    cell.className = "cellStyle" ;
    tableRow = document.getEle mentById(theTab leRowId);
    tableRow.append Child(cell);

    How would I get the left position of each cell added?

    Any help appreciated. Thanks.

    -Ted



  • Martin Honnen

    #2
    Re: Find left position of table cell



    ted wrote:

    [color=blue]
    > I have a table with a single cell. When a button is clicked, I'd like to add
    > another cell to it, give the cell a class style and then find the cell's
    > left position.
    >
    > Right now I'm using doing this:
    >
    > cell = document.create Element("td");
    > cell.appendChil d("sometext") ;
    > cell.className = "cellStyle" ;
    > tableRow = document.getEle mentById(theTab leRowId);
    > tableRow.append Child(cell);
    >
    > How would I get the left position of each cell added?[/color]

    You can get the position of any element in the document the same way (in
    IE 4+, Netscape 6+, Mozilla, Opera 7+) by adding the offsetLeft and
    offsetTop values along the offsetParent hierarchy, e.g. assuming element
    is a reference to the element
    var coords = { x: 0, y: 0 };
    while (element) {
    coords.x += element.offsetL eft;
    coords.y += element.offsetT op;
    element = element.offsetP arent;
    }
    // check coords.x, coords.y here
    Doesn't depend on whether it is a cell.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • ted

      #3
      Re: Find left position of table cell

      Thanks Martin.

      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:41e93e2c$0 $23139$9b4e6d93 @newsread2.arco r-online.net...[color=blue]
      >
      >
      > ted wrote:
      >
      >[color=green]
      >> I have a table with a single cell. When a button is clicked, I'd like to
      >> add another cell to it, give the cell a class style and then find the
      >> cell's left position.
      >>
      >> Right now I'm using doing this:
      >>
      >> cell = document.create Element("td");
      >> cell.appendChil d("sometext") ;
      >> cell.className = "cellStyle" ;
      >> tableRow = document.getEle mentById(theTab leRowId);
      >> tableRow.append Child(cell);
      >>
      >> How would I get the left position of each cell added?[/color]
      >
      > You can get the position of any element in the document the same way (in
      > IE 4+, Netscape 6+, Mozilla, Opera 7+) by adding the offsetLeft and
      > offsetTop values along the offsetParent hierarchy, e.g. assuming element
      > is a reference to the element
      > var coords = { x: 0, y: 0 };
      > while (element) {
      > coords.x += element.offsetL eft;
      > coords.y += element.offsetT op;
      > element = element.offsetP arent;
      > }
      > // check coords.x, coords.y here
      > Doesn't depend on whether it is a cell.
      >
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/[/color]


      Comment

      Working...