Note that these only work in the developer tools of certain browsers.
$_
gives you the value of whatever expression was evaluated last.
"foo" // "foo"
$_ // "foo"
$0
refers to the DOM element currently selected in the Inspector. So if <div id="foo">
is highlighted:
$0 // <div id="foo">
$0.getAttribute('id') // "foo"
$1
refers to the element previously selected, $2
to the one selected before that, and so forth for $3
and $4
.
To get a collection of elements matching a CSS selector, use $$(selector)
. This is essentially a shortcut for document.querySelectorAll
.
var images = $$('img'); // Returns an array or a nodelist of all matching elements
ยน alias to either document.getElementById
or document.querySelector