Selecting only `td` elements from the root table (not nested tables inside the root table)

Hey! i have a ref to a table element and I want to querySelectorAll its td in a certain index. I came up with the following:
tableRef.current.querySelectorAll<HTMLTableCellElement>(
`tbody tr td:nth-child(${index + 1})`
)
tableRef.current.querySelectorAll<HTMLTableCellElement>(
`tbody tr td:nth-child(${index + 1})`
)
it works very nicely but it also selects td elements from nested drawer tables, (which are basically the same table inside a certain tr). I want to select only the tds of the root table. Can someone assist me? i'm open to JS and CSS solutions
4 Replies
nanorise
nanoriseOP10mo ago
tr elment with nested table can be identified because it has a data-state="open" attribute
Y7YA
Y7YA10mo ago
if they can be identified like that, could you do tbody tr:not([data-state="open") td:nth-child(${index + 1})
nanorise
nanoriseOP10mo ago
I think its a step into the solution but it doesn't work. because the inner table is the same table so it still has tr > table > **tbody > tr > td** like the root table. I guess the only way to determine a row in the inner table from the outer table is that it has 2 parent tables instead of one? not sure if theres a css selector for taht @Y7YA
Y7YA
Y7YA10mo ago
you can use :has for that type of selection
Want results from more Discord servers?
Add your server