I want to search for all elements with class needle
in all elements returned by jQuery('.haystack')
and have tried jQuery('.haystack .needle')
, but this doesn't seem to pick up the case where an element has both classes. Is there a selector that will do this?
Try combining selectors:
jQuery('.haystack.needle, .haystack .needle');
This will select all .haystack
s that are also .needle
s and any .needle
which is a descendant of a .haystack
, which I think is exactly what you asked for :-)