I'm trying to query an element and its children to find ID's that begin with a particular string.
var foundIDs = containerElement.find('[id^=something]').andSelf().filter('id^=something');
The find()
method only searches descendants so I thought I'd try andSelf()
. However, andSelf()
does not take a selector. This means that the container element is included regardless of whether it matches the find query or not and I then have to perform a secondary filter()
on it to remove the container element if it didn't match after all.
I attempted to put andSelf()
before the find()
but it didn't seem to pick up the container element into the stack.
containerElement.andSelf().find('[id^=something]');
Is there any better way to achieve what I'm doing?