Table cell elements

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

    #1

    Table cell elements

    I need to be able to dynamically change the contents of a table cell (e.g.
    the text between <td> and </td>. I've been searching the web, but haven't
    found the solution to this one.

    I know the rows index and the cells index in the row. What do I need to do
    to affect the contents?

    Tremendous thanks in advance
    ---Michael


  • Martin Honnen

    #2
    Re: Table cell elements



    Michael Satterwhite wrote:
    [color=blue]
    > I need to be able to dynamically change the contents of a table cell (e.g.
    > the text between <td> and </td>. I've been searching the web, but haven't
    > found the solution to this one.
    >
    > I know the rows index and the cells index in the row. What do I need to do
    > to affect the contents?[/color]

    A td element object is not different to other element objects meaning
    you can use the usual browser stuff like manipulating innerHTML or like
    using the W3C DOM e.g. appendChild, insertBefore, replaceChild with
    appropriately created nodes (e.g. document.create Element('p'),
    document.create TextNode('Kibol ogy')) to alter the content.
    If you have the table element object and the row and cell index then in
    the HTML DOM
    var cell = tableElement.ro ws[rowIndex].cells[cellIndex]
    gives you the cell, then a cross browser and short way to replace its
    contents with some HTML snippet is
    cell.innerHTML = '<p>Kibology for all.<\/p>';

    --

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

    Comment

    • Mick White

      #3
      Re: Table cell elements

      Martin Honnen wrote:
      [snip]
      [color=blue]
      > var cell = tableElement.ro ws[rowIndex].cells[cellIndex]
      > gives you the cell, then a cross browser and short way to replace its
      > contents with some HTML snippet is
      > cell.innerHTML = '<p>Kibology for all.<\/p>';[/color]


      Caveat:
      "cellIndex" always returns 0 (zero) in Safari ( in 1.0.3, at least).
      "rowIndex" is probably equally crippled.
      Mick

      Comment

      Working...