SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast rjahrman's Avatar
    Join Date
    May 2003
    Location
    Washington, USA
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Enumerate All Cells Within a Table?

    I've done a "var tables = IFRAME_doc.all.tags('TABLE');", and now I have a "tables[t]". How can I enumerate all of the cells within that table (and loop through each and access it as an object)?

    I'm sure that this is really simple, but I'm fairly new to using the DOM . . .

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    for (i=0;i<tables.length; i++) {
      ...
      // code to run where tables[i] is object
      ...  
    }
    From the English nation to a US location.

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by rjahrman
    I've done a "var tables = IFRAME_doc.all.tags('TABLE');", and now I have a "tables[t]". How can I enumerate all of the cells within that table (and loop through each and access it as an object)?

    I'm sure that this is really simple, but I'm fairly new to using the DOM . . .
    1. That's the IE DOM, not the standard DOM. Don't expect that to work anywhere but IE.

    2. Here's the standards-based DOM solution:
    Code:
    var tables = document.getElementsByTagName("table");
    var thisTable, i=0, j=0, k=0, thisRow, thisCell;
    //this will loop through all the tables on your page.
    while (thisTable = tables[i++]) {
      //this will loop through all the rows in the current table.
      while (thisRow = thisTable.rows[j++]) {
         //this will loop through all the cells in the current row.
         while(thisCell = thisRow.cells[k++]) {
    
          }
          //reset the cell counter
          k = 0;
      }
      //reset the row counter
      j = 0;
    }
    Hope this helps!

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very handy

    Nice work, Vinnie.

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by MikeFoster
    Very handy

    Nice work, Vinnie.
    I've been doing a lot of work with data tables and JS lately .

  6. #6
    SitePoint Enthusiast rjahrman's Avatar
    Join Date
    May 2003
    Location
    Washington, USA
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    I don't really care about anything but IE due to the application (a WYSIWYG editor--the features are just about impossible with anything but IE).

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by rjahrman
    Thanks.

    I don't really care about anything but IE due to the application (a WYSIWYG editor--the features are just about impossible with anything but IE).
    HTMLArea works in Mozilla as well as IE.

  8. #8
    SitePoint Enthusiast rjahrman's Avatar
    Join Date
    May 2003
    Location
    Washington, USA
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm . . . I'll look into it to see how they did it.


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
  •