Skip to content
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

Find element parent by selector #164

Merged
merged 3 commits into from
Jan 12, 2021
Merged

Find element parent by selector #164

merged 3 commits into from
Jan 12, 2021

Conversation

Dakror
Copy link
Contributor

@Dakror Dakror commented Jan 12, 2021

Currently there are selection methods to find children by selector but not recursive parents, so I added one.

Since the methods for query selector parsing are implementation-private, I couldnt actually do this in my own project, so why not create a PR. (exposing those functions could be another nice addition)

@mikke89
Copy link
Owner

mikke89 commented Jan 12, 2021

Thanks for the PR! I was wondering how useful this is, especially since I couldn't even find it on the HTML DOM. But then I found there is indeed one, but it's called Element.closest().

I say we stick to the HTML terminology and call it Element::Closest, however bad that is :P

Also, we might as well support multiple selectors, it shouldn't be much slower as we have already created the nodes. I also suggest we add a performance warning like in the QuerySelector functions, and rename the description such that parent -> ancestor.

Thanks again, it's always nice to see more contributions!

@mikke89 mikke89 added the enhancement New feature or request label Jan 12, 2021
@Dakror
Copy link
Contributor Author

Dakror commented Jan 12, 2021

To be honest i was just so used to this function in jQuery :D

@mikke89 mikke89 merged commit 15361e3 into mikke89:master Jan 12, 2021
@mikke89
Copy link
Owner

mikke89 commented Jan 12, 2021

Awesome, thank you!

@Dakror Dakror deleted the findparent branch January 13, 2021 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants