:has() is a very useful tool in CSS that is ready to use.
It often allows you to remove JS—for example by linking :hover in one branch of the DOM tree with a reaction in another.
See how we at oklch.com threw away a lot of JS code
https://github.com/evilmartians/oklch-picker/pull/157
