en.javascript.info
en.javascript.info copied to clipboard
Add CSS.escape() to DOM searching chapter
Hello, I was wondering if it would be worth adding something in the chapter Searching: getElement, querySelector about how to pass a variable through document.querySelector by using CSS.escape(), ie document.querySelector('div.' + CSS.escape(userColor))
I write this because I just spent a while trying template literals, etc, and I had no idea CSS.escape() existed and is necessary to do this.
It's probably pretty uncommon to need to pass variables to querySelector, but if anyone else thinks it's worth adding I would be happy to make a PR.
https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape