4

When you click on "Inspect an element" or on an element in the console you can see == $0 next to him.

What does this stand for ? What is the utility ?

You can type $0 in the console and it will output the element but how are you suppose to use it ?

Baldráni
  • 5,332
  • 7
  • 51
  • 79
  • 1
    First result in google: https://willd.me/posts/0-in-chrome-dev-tools – vaso123 May 18 '16 at 13:20
  • @lolka_bolka yeah I've seen this, I've also seen the third next answer Im not completely dumb and so on I've read that you can use it. Then my question is what is the utility ? – Baldráni May 18 '16 at 13:59

1 Answers1

13

It's useful for debugging and playing around with elements using the Console API. If you select an element in the Elements panel, it gets added to a stack of index references. $0 refers to the last selected element, $1 is the one selected before that, and so on. It remembers the last five elements $0 - $4.

This means you can quickly call functions, or change attributes and properties of these previously selected elements without needing to use a selector like document.getElementById('hplogo'); or $('#hplogo'). Example below:

Google

Gideon Pyzer
  • 22,610
  • 7
  • 62
  • 68
  • So this refer as a javascript selector and can be freely use as if it was one ? Nice one I'll remember to try it ! – Baldráni May 18 '16 at 16:43
  • @Baldráni Yes, there are other useful features you can read about in the Console API. They are there to make your life slightly easier, as debugging can often be time consuming pain :) – Gideon Pyzer May 18 '16 at 16:49