SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can somebody help me understand the Table Object Model

    I am trying to dynamically manipulate tables and it is working in FF but apparently tables are read only in IE. So I have to use the TOM and drill down to the cells.. I've sniffed around over at microsoft and their documentation was only somewhat helpful. What I need to do is change the innerHTML of cells within a table and I can't quite figure it out.

    For example: How would I change this
    <table width="100&#37;" border=0 cellspacing=0 cellpadding=0><TR>

    <td> Some content </td>

    </TR></table>
    to this

    <table width="100%" border=0 cellspacing=0 cellpadding=0><TR>

    <td>New Content</td>

    </TR></table>
    Also desirable (but not as important would be some help on changing the table width dynamically).

    Thanks in advance.

    EDIT: BTW, for reasons I won't trouble you with, I have to use the GetElementsByTagName call to access the table.

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I figured it out and here it is for anybody who finds this thread using search

    var mytable = document.getElementsByTagName("table")[0];
    var mytablebody = mytable.getElementsByTagName("tbody")[0];
    var myrow = mytablebody.getElementsByTagName("tr")[0];
    var mycel = myrow.getElementsByTagName("td")[0];

    mycel.innerHTML = 'New HTML';
    Your indexes may change accordingly but the code itself works (both IE and FF). Still trying to figure out how to change the width (and background also).

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Third Stone From The Sun
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by snarky View Post
    trying to figure out how to change the width (and background also).
    Code:
    mytable.style[ prop ]
    replace prop with "width", "backgroundColor", et c.
    My outdated site is down for a while now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •