en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

Add CSS.escape() to DOM searching chapter

Open robertmcabee opened this issue 3 years ago • 0 comments

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

robertmcabee avatar Feb 05 '22 05:02 robertmcabee