DevTools Tips

Categories: Supported by:

Store a node as a variable to use it in the console

If you want to use a DOM node from the page in the console:

The Console opens up, pre-filled with a new variable name (something like temp1) which you can use to refer to the node any time you want.

Note that if you only want to refer to the currently selected node (and not create a new variable), you can also use $0 in the console.

screenshot of firefox's "use in console" context menu option in the Inspector, and also showing the Console with a couple of tempN variables

Thank you Austin Gil for sharing this tip on Twitter!