3 ms·
Here's a really obscure one which I've never heard anyone mention, except the first time I heard about it: In the JS console: $0 is a reference to the curr
by amatecha 5y ago
Here's a really obscure one which I've never heard anyone mention, except the first time I heard about it:
In the JS console:
$0
is a reference to the currently-highlighted element in the DOM Inspector (at least this is the case in Firefox, Chrome and Edge, haven't tried others).
Very handy for quickly evaluating or operating on an element you're looking at :)
- iudqnolq 5y agoIn a similar vein you can right click on any logged value that's pretty printed in color and save it to a global variable to play around with. (console.log("foo", foo) works with this, console.log("foo"+foo) doesn't)
- jakear 5y agoYou'll see that in the Elements panel, it actually puts a grey " == $0" after the selected element to point you towards this feature. Also, $1 is the previously selected element, $2 is the one before that, etc.
- chriscodepo8 5y agoAuthor here. There are even more. $0 is only the current one, but you also have $1 to $4 as a history of the last ones/ I like that $_ is a reference to the last result of what you did in the console. I documented most here: https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/console/utilities https://docs.microsoft.com/en-us/microsoft-edge/devtools-gui...
- amatecha 5y agoNice, that's great to know! Thanks for capturing them on that page. BTW I've followed you on Twitter for years. Always lots of neat tips and interesting topics -- thanks for that! :)
- wonnage 5y agoIf you’re using React the same applies in the dev tools component tree - $r is the currently highlighted component.