ooze1992
ooze1992

Reputation: 25

Access element in the next adjacent table using index

I am new to jQuery and I am trying to accomplish something that I have not found an answer. I have two adjacent tables with the exact same # of rows and columns. When I click on an element in one table, I want to access the same element in the other table. So far, I can figure out what row index I am in the current table but I can't seem to go to the next table. Here is the layout of my table:

table1

row col1 col2
1    a    b 
2    c    d
3    e    f

table2

row col1 col2
1    w    x
2    y    z
3    n    m

For example, If I click "a" in table 1, I want to know what is the value in the element "w". I appreciate any help. Thanks.

Upvotes: 2

Views: 74

Answers (1)

Cristiano
Cristiano

Reputation: 2909

You could make each table element have an id, where that id is something along the lines of "{tableNum}-{row}-{col}". This would make it easy to access each element by its id.

If you were to see that a had been clicked, you would get back that element and access the element in the other table using $("#table2-1-1"). Let me know if I worded this poorly.

Upvotes: 1

Related Questions