It's a sad state of affairs because it's a regression.
This was trivial for websites 15 years ago, but due to increasing complexity, it's no longer feasible. We've put more and more styling type things in JS, which really undermines web as a platform.
This is why CSS exists. This isn't some weirdo use case, this is THE use case. We're all losing the plot.