Question

I need to select and act on a table element with JQuery, but only when it contains at least one row with more than one column. The following selector works, but only gets me part way:

$('#my_table_is:has(tbody tr)').doSomething();

Variations I have tried with no success are:

$('#my_table_id:has(tbody > tr > td:eq(1))').doSomething();
$('#my_table_id:has(tbody tr:nth-child(1))').doSomething();
$('#my_table_id:has(td:eq(1))').doSomething();    

What combination of selector and filter will make this work?

BTW, the reason I need this is that tablesorter with a multi-column sortList, will apparently blow up when there is only 1 column in the table output.

Was it helpful?

Solution

how about just a good ole check?

if (1 < $('#tbl thead th').size()) ...

OTHER TIPS

Would it not be easier to actually fix the tablesorter instead of hacking around? (I assume you mean http://tablesorter.com/).

I managed to do this with the following selector (also for an old version of TableSorter):

#tableID:has( tbody > tr > td + td )

The idea is that it will find the table only if it has a tbody with a tr that has at least two sibling td in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top