0

I am just on http://example.com - literally the reserved example domain.

I opened the console and typed $('body')↙

I got this:

dollar-sign

I am pretty sure this page has NO jquery loaded. To make sure it has nothing to do with my Chrome extensions, I tried Safari, Opera, and Firefox. All got the same results. Why the dollar sign still works? Is the $ a new JavaScript native function now?

AGamePlayer
  • 7,404
  • 19
  • 62
  • 119

1 Answers1

5

All Chromium-based browsers (Google Chrome, Microsoft Edge, etc) have a set of utility functions in the Developer Tools console window - this includes $() as an alias of querySelector, which has the same name as jQuery's $ (jQuery) object.

They are documented here: https://developers.google.com/web/tools/chrome-devtools/console/utilities

$_
$0
$1
$2
$3
$4
$
$$
$x
clear
copy
debug
dir
dirxml
inspect
getEventListeners
keys
monitor
monitorEvents
profile
queryObjects
table
undebug
unmonitor
unmonitorEvents
values
  • Note that these utility functions cannot be used from page scripts (<script>): they can only be used in the Developer Tools console.
  • If a page does include a function with the same name as a Developer Tools utility function then the page's functions take precedence over the utility functions
    • So if a page uses jQuery, then $ will be jQuery's, not Chrome's.

This is not the same as the console. API, like console.log, console.error, etc, which are part of the browser API.

Dai
  • 141,631
  • 28
  • 261
  • 374