What is “$” in Chrome console?

耗尽温柔 提交于 2021-02-05 08:09:59

问题


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 $.


回答1:


$ 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.



来源:https://stackoverflow.com/questions/45757627/what-is-in-chrome-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!