Writing someting in a table cell through Javascript

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

    Writing someting in a table cell through Javascript

    Hi!

    Could anybody help me guide how to write something in between <td></
    tdtags. When I try to write through document.write, it wipes the
    whole table and writes on to a blank document, but when I try with
    document.getEle mentById("respe ctive id given by me").write, it gives
    Error on page.

    I'm bit puzzled. Can anyone of you help me.

    Thanks in advance
    Vasu
  • Martin Honnen

    #2
    Re: Writing someting in a table cell through Javascript

    Vasu wrote:
    Could anybody help me guide how to write something in between <td></
    tdtags.

    Get a reference to the table cell object e.g. with
    var cell = document.getEle mentById('cellI d');
    then append text with
    cell.appendChil d(document.crea teTextNode('foo '));
    If you want to insert HTML then you can use the innerHTML property e.g.
    cell.innerHTML = '<b>foo</b>';

    Both approaches are not specific to td elements.

    --

    Martin Honnen

    Comment

    • Vasu

      #3
      Re: Writing someting in a table cell through Javascript

      On Aug 4, 3:55 pm, Martin Honnen <mahotr...@yaho o.dewrote:
      Vasu wrote:
      Could anybody help me guide how to write something in between <td></
      tdtags.
      >
      Get a reference to the table cell object e.g. with
         var cell = document.getEle mentById('cellI d');
      then append text with
         cell.appendChil d(document.crea teTextNode('foo '));
      If you want to insert HTML then you can use the innerHTML property e.g.
         cell.innerHTML = '<b>foo</b>';
      >
      Both approaches are not specific to td elements.
      >
      --
      >
              Martin Honnen
             http://JavaScript.FAQTs.com/
      Hi Martin!

      Thank you very much! I tried and it's working.

      Vasu

      Comment

      Working...