Suppose we are given the following element:
var cachedElement = $('<div><p>Some text</p></div><aside>Some more text</aside>');
If I know what is in the element, I can easily go through it. For example, to find a div, I can use:
cachedElement.filter('div');
and find the child that I can use:
cachedElement.find('p');
What if I do not know the structure of the cached element. How to look for an element that can be parent, child, or both.
I was wondering if there is a way that can do this for me. I don't want to wrap an element in a div and search with .find ().
My best solution is the following inefficient (and ugly) selector:
cachedElement.filter('selector_string').add(cachedElement.find('selector_string')).eq(0)
In my specific case, I only need the first element.
Any ideas? Thanks
source share