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
$_ | $()¹ | $$() | $0 | $1 | $2 | $3 | $4 | |
---|---|---|---|---|---|---|---|---|
Opera | 15+ | 11+ | 11+ | 11+ | 11+ | 15+ | 15+ | 15+ |
Chrome | 22+ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Firefox | 39+ | ✓ | ✓ | ✓ | × | × | × | × |
IE | 11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 |
Safari | 6.1+ | 4+ | 4+ | 4+ | 4+ | 4+ | 4+ | 4+ |
¹ alias to either document.getElementById
or document.querySelector