How to get an element into a variable in the dev console
What's the easiest way to put an HTML element into a variable in the browser dev console?
I usually use this pattern:
- inspect the element, right click > copy selector path
- open the console,
foo = document.querySelector('cmdv')
But this doesn't work when the selector path has escaping, e.g.
#root > div > div.hidden.sm\:block.w-\[250px\] > div > div > div
JavaScript doesn't have literal strings, and I don't know how to double-escape backslashes when I paste a string into the console.