Chrome dev tools: access to DOM element pointer $ 0 from bookmarklet / snippet

Is it possible to access the $ 0 DOM element pointer from a bookmarklet or fragment in the console.?

Additional Information on $ 0

https://developers.google.com/chrome-developer-tools/docs/commandline-api#0_-_4

Dev Tools remembers the last five DOM elements (or JavaScript heap objects) that you selected on the tab (or profile panel). This makes these objects available as $ 0, $ 1, $ 2, $ 3, and $ 4. $ 0 returns the last selected element or JavaScript object, $ 1 returns the second most recently selected, etc.

+7
javascript google-chrome google-chrome-devtools
source share
3 answers

I was looking for a way to do this too. I did not find one, but I found a good compromise to be a bookmarklet that copies a piece of code to the clipboard. I use $ 0 with angular to get the volume of an element, for example: angular.element ($ 0) .scope ()

So, I have a bookmarklet that copies this line to my clipboard, then I can very easily paste it into the console. Depending on what you want to use $ 0 for, this might do the trick for you.

Here is a link to how to copy text to clipboard using javascript: How to copy to clipboard in JavaScript?

0
source share

In the bookmark, I just used angular.element(this.document) instead of angular.element($0) , and it worked for me.

0
source share

This is similar to Chrome 65.

I have a fragment that starts:

 console.log('$0 points to', $0); 

In GIF (right click> Open image in new tab if it is too small), you can see that the link is updated every time I select a new item and then re-run the snippet. FYI I run a snippet from the command menu by typing ! and then the name of the script.

enter image description here

0
source share

All Articles