user3280015
user3280015

Reputation: 279

How can you select elements that contain exactly descendants that match a given selector?

For example, to select all cells of a table which contain only elements matching a selector selector, I tried:

$('table tr td:has(' + selector + ')')

but this also matches cells also containing other stuff.

Then I tried:

$('table tr td:has(' + selector + '):not(:has(:not(' + selector + ')))')

But this always returns an empty object.

What am I doing wrong?

EDIT: Thanks guys, actually I was doing something wrong it seems, because trying with a minimal fiddle, it does seem to work using the second approach: http://jsfiddle.net/u0r6oehc/1/

Upvotes: 0

Views: 48

Answers (1)

Selo
Selo

Reputation: 250

Not sure if I understood correctly but you want all td's who has a child with a certain class for ex?

Maybe using :has()

Fiddle

Edit: saw your edit now ;)

Upvotes: 1

Related Questions