SBB
SBB

Reputation: 8970

jQuery class NOT IN table

I have a page with several tables. I am allowing a user to add data points to the page if they haven't yet been used on the page.

All of the tables have a column with the class of field.

When I am providing them with the list of options to add, I want to ignore a specific table.

Basically, I want to loop over all .fields that are not in the table #groupTable.

$('.field:not(#groupTable)').each(function(){
    if(parseInt($(this).text()) == parseInt(fieldID)){
        inUse = true;
    }
});

Is there something I am missing from my selector? With how it is currently shown, it is including results from the #groupTable.

Upvotes: 1

Views: 46

Answers (3)

Josh Crozier
Josh Crozier

Reputation: 241118

You are trying to exclude .field elements with an id of #groupTable.

Try excluding table elements with an id of #groupTable, then selecting the .field descendant element(s):

$('table:not(#groupTable) .field').each(function () {
  // ...
});

Upvotes: 2

p. leo
p. leo

Reputation: 48

I created a jsfiddle

This is the selector: .field:not(#groupTable .field)

Upvotes: 0

andrew
andrew

Reputation: 9583

Yes, you are missing something, your selector excludes the table itself, to exclude the columns from within it I would think your selector should be:

'.field:not(#groupTable .field)'

Upvotes: 2

Related Questions