-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: new method Elements.parents() #20
Comments
Thanks, that looks like a good idea. It's kind of odd that there's not a native CSS selector syntax to find parents based on their children. Might also be good to implement jquery's |
Heh, well I guess you'll end up implementing all of jQuery's selection and traversing methods at some point ;) As for CSS, I read an article once on that subject of "parent selectors", the supposed reason being that it's really hard for browsers to implement (or implement efficiently, at least). |
Just to clarify if it wasn't clear: in jQuery, I don't know what your approach is with regard to the functions acting on |
Thanks. I would look to mirror most functions from Element into Elements where it makes sense -- in this case it would be the combined set of all parents. |
Added :has(selector) pseudo-selector. Closed by 49f0e41 |
Added Element#parents() and Elements#parents() methods. Fixes jhy#20
Added Element#parents() and Elements#parents() methods. Fixes jhy#20
A function similar to jQuery's parents() - http://api.jquery.com/parents/ - would be a nice addition. The function would return all parent elements of the current Element. Or, given an optional parameter, would filter based on that.
So if you for example selected all bold text with
Elements elems = doc.select('b')
you could then find all bold tags that were in paragraphs withelems.parents('p')
, and that would select the paragraphs themselves if you wanted to do some processing on them.You could also add the optional selector to the parent() function too - although it is as easy in this case to simply select the parent and check if the tag or class etc matches.
The text was updated successfully, but these errors were encountered: