Javascript: get content of table's cell (inside div)

Gytis TG

I have a little problem with finding cell's id (and its content). Main table contains multiple divisions and each division contains one table with several cells. What I want is to display cell with id content_xx. My tables look like this:

<table id="MainTable">                  // Main (global) table

 <div id="divid_1">                     // First div in main table
  <table id="InfoTable">                // First div's table
   <td id="title_10">CellTitle</td>     // Cell #1
   <td id="content_11">CellContent</td> // Cell #2

 <div id="divid_2">                     // Second div in main table
  <table id="InfoTable">                // Second div's table
   <td id="title_20">CellTitle</td>     // Cell #1
   <td id="content_21">CellContent</td> // Cell #2

 // etc...
</table>

Function for finding it:

function FindContent(id)
{
    t = document.getElementById("InfoTable").rows[0].cells.namedItem("content_"+id).innerHTML;
    alert(t);
    return;
}

I have onclick event which executes this function. It works for me only for first InfoTable, but it does not work when I try same thing on table #2 or further. I get this error: TypeError: document.getElementById(...).rows[0].cells.namedItem(...) is null. How can I fix this and why it does not work? Is it because of row[0]? If I change to row[1], for example, then it doesn't work at all. I can change structure of html but not completely.

Gytis TG

** Solved by icecub **

The problem was that I was using same ID in divs, therefore, only first table would have been returned. I just needed to use different ID.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

get content inside a div inside a data object

From Dev

Get table cell content based on content of cell in neighbourhood

From Dev

How to align div on the bottom inside table cell

From Dev

Access contents of div inside table cell

From Dev

Table formatting based on cell content in Javascript

From Dev

How to get ALL id's inside of a DIV using pure javascript

From Dev

Move the content, not text, of a table's cell to the right

From Dev

Manage text overflow with a span inside a div inside a table cell

From Dev

Get the value of Table's td content when clicked on some input type that is inside other td of the same table

From Java

height: 100% for <div> inside <div> with display: table-cell

From Dev

How can I get two UL's in table-cell-formatted DIV's to be flush against the top?

From Dev

Forcing table inside table-cell div to be fill 100% width

From Dev

Get value inside Div Javascript

From Dev

Display HTML content inside a table cell - BIRT report designer

From Dev

How to center horizontal table-cell and content inside it in the middle

From Dev

How to get all td cell 's content values from many tables, using javascript?

From Dev

Content Margin Depend on Other Div by Using Display Table-Cell

From Dev

100% height div inside table-cell not working on Firefox

From Dev

Truncating text into ellipsis in a fluid div inside table-cell

From Dev

Horizontal align link inside div with table-cell property

From Dev

Expand div inside table cell like dropdown menu

From Dev

100% height div inside table-cell not working on Firefox

From Dev

Horizontal align link inside div with table-cell property

From Dev

Truncating text into ellipsis in a fluid div inside table-cell

From Dev

Get the value of a table cell in javascript with external script

From Dev

Get Table Cell values and pass to Javascript

From Dev

get div class by content inside div using C#

From Dev

How to transclude div's content as a table header?

From Dev

Get content of specific Table cell and change text color

Related Related

  1. 1

    get content inside a div inside a data object

  2. 2

    Get table cell content based on content of cell in neighbourhood

  3. 3

    How to align div on the bottom inside table cell

  4. 4

    Access contents of div inside table cell

  5. 5

    Table formatting based on cell content in Javascript

  6. 6

    How to get ALL id's inside of a DIV using pure javascript

  7. 7

    Move the content, not text, of a table's cell to the right

  8. 8

    Manage text overflow with a span inside a div inside a table cell

  9. 9

    Get the value of Table's td content when clicked on some input type that is inside other td of the same table

  10. 10

    height: 100% for <div> inside <div> with display: table-cell

  11. 11

    How can I get two UL's in table-cell-formatted DIV's to be flush against the top?

  12. 12

    Forcing table inside table-cell div to be fill 100% width

  13. 13

    Get value inside Div Javascript

  14. 14

    Display HTML content inside a table cell - BIRT report designer

  15. 15

    How to center horizontal table-cell and content inside it in the middle

  16. 16

    How to get all td cell 's content values from many tables, using javascript?

  17. 17

    Content Margin Depend on Other Div by Using Display Table-Cell

  18. 18

    100% height div inside table-cell not working on Firefox

  19. 19

    Truncating text into ellipsis in a fluid div inside table-cell

  20. 20

    Horizontal align link inside div with table-cell property

  21. 21

    Expand div inside table cell like dropdown menu

  22. 22

    100% height div inside table-cell not working on Firefox

  23. 23

    Horizontal align link inside div with table-cell property

  24. 24

    Truncating text into ellipsis in a fluid div inside table-cell

  25. 25

    Get the value of a table cell in javascript with external script

  26. 26

    Get Table Cell values and pass to Javascript

  27. 27

    get div class by content inside div using C#

  28. 28

    How to transclude div's content as a table header?

  29. 29

    Get content of specific Table cell and change text color

HotTag

Archive