I want to select <td>
elements that contain only a checkbox. I want to do this with a single selector (not using chaining or logic outside the selector) so that I can use the selector with jQuery functions like live
or delegate
.
The bigger pictures is that I want to listen for a click event on these <td>
s and pass the click event on to the checkbox, thus creating a larger clicking area. This is important, because the <tr>
also has a different click event that I don't want to activate when users click and miss the checkbox.
I created a jsfiddle with an example scenario: http://jsfiddle.net/ytA3X/
This is what I started with that is not working. In other words, select any td element that has a checkbox but does not have anything that is not a checkbox.
$('td:has(:checkbox):not(:has(:not(:checkbox)))')
=> []
:not(:has(...))
works in my jsfiddle example.
:has(:not(...))
works in my jsfiddle example.
:not(:has(:not(...)))
always seems to select nothing.
Is there a different way that I can select td elements with only a checkbox, or am I doing something wrong?
How about using :only-child
:
$('td:has(:checkbox:only-child)')...
JSFiddle
You can use the only-child
selector:
$('td:has(:checkbox:only-child)')
Here it is in use with your markup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With