Need JQuery to select the table only if its 1st row has more than 1 column

I need to select and act on a table element using JQuery, but only if it contains at least one row with multiple columns. The following selector works, but only part of it gets me:

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

      

Variations I've tried without success:

$('#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 do the job?

By the way, the reason I need this is because a tablesorter with a multi-column sorter seems to blow up when only 1 column is outputted in the table.

0


source to share


3 answers


how about a good ole checkout?



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

      

+1


source


Wouldn't it be easier to actually fix the tablesorter instead of hacking it? (I assume you mean http://tablesorter.com/ ).



0


source


I was able to do it with the following selector (also for the old version of TableSorter):

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

The idea is that it will only find the table if it has a tbody

c tr

that has at least two siblings in it td

.

0


source







All Articles