tags:

views:

419

answers:

1

I'm currently writing a filter for a selectable, I have some table cells that contain divs.

the divs have a classes named start middle & end.

essentially I want to filter out table cells that contain the div "middle", or contain BOTH "start" and "end". however, if the cell contains only "start" or "end", then it should still be selectable.

I've got the following so far,

$("#someTable tbody tr").selectable({ 
    filter: 'td:not(td:has(div.middle),
    td:has(div.start,div.end))', 
    });

but I cant figure out how to get the line

td:has(div.start,div.end))'

to do div.start AND div.end, as it's matching cells that contain either at the moment...

any help would be greatly appreciated!

+2  A: 

To find elements with both a .start and .end in them, you can use:

:has(div.start):has(div.end)

In all, you could do:

$("#someTable tbody tr td").not(':has(div.start):has(div.end)').not(':has(div.middle)');
VoteyDisciple
don't know why you got downvoted. Your solution works perfectly. +1
peirix
This is totally inefficient way of doing that. Having two :has will cause jQuery to loop through all the elements twice and in large DOM this will be very slow, what you should do is to combine this into one `:has(div.start.end)` filter
RaYell
ahhh I just needed to chain them... thanks!
Zeus
RaYell: That selector fundamentally only matches a **single** element that has **both** classes. We're looking for **two separate elements**, each with **one** of the classes.
VoteyDisciple
what VoteyDisciple said is correct :)
Zeus
If that is so your code won't work either. They are exactly the same.
RaYell
also, the reason my initial selector has only $("#someTable tbody tr") in it, without the td, is so that only one row is selectable at a time, in case anyone was wondering.
Zeus
@RaYell: `has(div.start.end)` selects a td which has a div that has both start and end class inside, while `has(div.start):has(div.end)` selects a td which has one div of class "start", and ANOTHER div which has class of "end". Your way: one div with BOTH classes, this way, two divs with one class EACH. There is a difference.
peirix