Jagajit Prusty
Jagajit Prusty

Reputation: 2110

What is "$" in Chrome console?

When we type $ in chrome console it returns a function. I am sure it's not jQuery's $.
If I want to use jQuery in console, What is the best way to trigger jQuery in chrome console as $.

Upvotes: 1

Views: 2564

Answers (1)

Ionică Bizău
Ionică Bizău

Reputation: 113345

$ is an alias for document.querySelector. In the same vein there is $$ which is an alias for document.querySelectorAll.

It is defined in the Command line (console) api.

Command Line API Reference

The Command Line API contains a collection of convenience functions for performing common tasks: selecting and inspecting DOM elements, displaying data in readable format, stopping and starting the profiler, and monitoring DOM events.

If you have $ defined on the page as a global (perhaps by using jQuery), you'll get that global, not the command-line built-in.

There are other handy functions defined there.


To run jQuery, without having it in the page source code, you may find Chrome extensions to be handy, or simply copy-paste the jQuery source code in the console.

Upvotes: 6

Related Questions