question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace `select().closest()` calls with `:has`

See original GitHub issue

The :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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
fregantecommented, Mar 15, 2022

5% of our users have it. 95% more to go.

FN3oQM8XoAEqduW

2reactions
fregantecommented, Aug 18, 2021

The advantage of just using sizzle is that we can drop it easily once :has() becomes available in every browser (2028)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found