The existing answers are outdated, $
is not an alias for document.getElementById
or document.querySelector
, but a wrapper for querySelector
. This wrapper actually takes an optional second argument for the element to query the child of.
For Chrome this family of functions is documented under the Console Utilities API reference:
$(selector [, startNode])
$(selector)
returns the reference to the first DOM element with the specified CSS selector. When called with one argument, this function is a shortcut for the document.querySelector() function.
$$(selector [, startNode])
$$(selector)
returns an array of elements that match the given CSS selector. This command is equivalent to calling Array.from(document.querySelectorAll())
.
$x(path [, startNode])
$x(path)
returns an array of DOM elements that match the given XPath expression.
Firefox also documents their implementation of these functions under Web Console Helpers (currently the same except $x
allows a 3rd argument).
I don't know if/where Safari/WebKit documents it, but it also implements them the same as Chrome.
Note that these values are only the default values within the console versus the page itself. For example if the page sets the variable by including jQuery that variable will take precedent and the console will use the value from the page itself so that $('p')
will return a jQuery object rather than just the first p
element.
$
(it was surprisingly hard), but I don't seefunction () { [native code] }
. Were you paused at a breakpoint? – Mordredabout:blank
, open the console and type$
then hit enter. – Fireback