Re: [csswg-drafts] [css-pseudo] Add a property to the `CSSPseudoElement` IDL interface to determine if a pseudo element "exists" (#12158)

I think we might want to have both approaches, the observer one for tracking async creation/removal of pseudos (to e.g. add event listeners), but I feel like we might still need the sync version as well, for example for:
- An author might need to know the state of pseudo right now, for example, say you have a copy button and in its event listener you only want to do something if there is a selection, that would be as easy as:
```
btn.onclick = () => {
  if (el.pseudo('::selection').exists) {
     copyToClipboard();
  }
}
``` 
- There might be some library/polyfill on a website that needs to be initialized. It might need to check if a pseudo is e.g. being rendered to fallback to poly filling it instead.
- Theoretically, but still... If an author is just looping through the tree/list of elements to e.g. generate some report or export some data, sync check might be useful there.
- I wonder if the observer with its creation/removal pattern makes sense for non-tree-abiding pseudos, which are more like states.
- An author might want to have a way to check the existence of a pseudo element in some unit testing. To e.g. check that the ::scroll-marker is really rendered.

-- 
GitHub Notification of comment by danielsakhapov
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/12158#issuecomment-3530477591 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 14 November 2025 01:53:01 UTC