Is this the best way to query an element and its children?
Posted
by Soviut
on Stack Overflow
See other posts from Stack Overflow
or by Soviut
Published on 2010-05-29T18:38:19Z
Indexed on
2010/05/29
18:42 UTC
Read the original article
Hit count: 136
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?
© Stack Overflow or respective owner