$ and $$ are now native browser functions?

Asked

Viewed 84 times

9

When using the console on a Javascript-free page I noticed that when typing $ had the same effect as document.querySelector and while typing $$ had the same effect as document.querySelectorAll.

Would be two shortcut functions for querySelector or they have some different specific behavior?

What are their names? I even looked in the kennel http://caniuse.com/#search=%24%24, but I didn’t get any results (I tried "dollar" as well)

  • These are methods that come with the console.

  • @bfavaretto would have a name? I searched for "dollar Sign"

  • @bfavaretto actually just asked the question even to exist on the site :p .. but if you have a dup to indicate I will be grateful

  • I also think it’s good to have the question on the site. I just don’t have time to research to put a decent answer now, so the first comment.

1 answer

9

These are console-only methods, shortcuts to facilitate the programmer.

This is confirmed in chrome documentation here and in the Edge documentation here where it says:

$() is a shortcut to Document.querySelector().
$$() is a shortcut to Document.querySelectorAll().
$0, $1, $2, $3, $4 returns the last elements selected by the DOM explorer (Elements)

There is still the $_ but this has a different behavior in Chrome and Edge:

Edge:

$_() is a shortcut to last object/element.

Chrome:

$_ is a shortcut to show the value of the last evaluated expression.

inserir a descrição da imagem aqui

Browser other questions tagged

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