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

7

When I inspected a page, I noticed that == $0 appears that is not part of HTML.

What does this code mean? Are you part of JavaScript?

    
asked by anonymous 27.07.2018 / 01:47

2 answers

5

Is the element that is selected. It can be referenced in the JavaScript console with the $0 variable. 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 here on the same Stack Overflow page). Of course, this is not limited to calling html() , you can do any DOM manipulations using $0 .

    
27.07.2018 / 01:56
5

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

Soon, in HTML:

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

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

document.getElementById('exemplo');

or

document.querySelector('#exemplo');

Among others

Just for the sake of curiosity, you can reference comments with $0 , just select it, but instead of returning an instance of HTMLElement , returns an instance of Comment

    
27.07.2018 / 01:59