Replace `select().closest()` calls with `:has`
See original GitHub issueThe :has()
CSS selector is nowhere to be seen yet and given the recent de-class-ification of GitHub’s DOM we found ourself needing code like this very often:
select('.some-octicon').closest('details')
"Custom API" suggestion, discarded. Sizzle is best
so I wonder how we can “polyfill” the selector without have to load Sizzle. Example:
select2('details').has('.some-octicon')
Example:
function select2(selector: string) {
return {
has(children: string) {
return select(children)?.closest(selector);
}
}
}
select2.all = (selector: string) => {
return {
has(children: string) {
return select.all(children) :filter/map: .closest(selector);
}
}
}
Thoughts? Worth it at all?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Replace select().closest() calls with :has #4456 - GitHub
The :has() CSS selector is nowhere to be seen yet and given the recent ... Replace select().closest() calls with :has #4456.
Read more >.closest() | jQuery API Documentation
This will change the color of list item A. The .closest() method begins its search with the element itself before progressing up the...
Read more >replacement for jQuery .closest() selector - Stack Overflow
replacement for jQuery .closest() selector [closed] · I don't see any information about it being deprecated or removed. Am I missing something?
Read more >Practical Use Cases for JavaScript's closest() Method
One solution would be to make use of a while loop that runs until the parent node has been found. function getParentNode(el, tagName)...
Read more >Difference between find() and closest() in jQuery
2. closest() Method: This method is used to get the first ancestor of the selected element. The ancestors can be parents, grand-parent, great- ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
5% of our users have it. 95% more to go.
The advantage of just using
sizzle
is that we can drop it easily once:has()
becomes available in every browser (2028)