What does "== $0" represent when inspecting a page?

Asked

Viewed 1,995 times

7

When inspecting a page, I realized it appears == $0 that is not part of HTML.

inserir a descrição da imagem aqui

What does this code mean? It is part of Javascript?

  • 4

    Greetings, Lorena. I took the liberty of editing your question in order to clarify the question about == $0. As for your other question, to keep the header fixed, I recommend you to open a new question, as it has no relation to this doubt.

  • Thank you so much. I’m sorry.

2 answers

5

It is the element that is selected. It can be referenced in the Javascript console with the variable $0. For example (using jQuery), if you type this in the console:

$($0).html()

The HTML of the element you selected will appear (you can test it here in the Stack Overflow page). Of course this is not limited to calling html(), you can do whatever manipulations you want in the DOM using the $0.

5

$0 is a javascript variable that the developer tools (dev tools) create to make our life easier, when used in the terminal it references the element selected in the tab elements, therefore the == $0, because the selected element is equal to $0

Logo, in an HTML:

<p id="exemplo">Exemplo</p>

Call $0 (having this element selected in dev tools) is equivalent to:

document.getElementById('exemplo');

or

document.querySelector('#exemplo');

Among others

For curiosity purposes only, it is possible to reference comments with the $0, just select it, however, instead of returning an instance of HTMLElement, returns an instance of Comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.