What is “$” in Chrome console?

前端 未结 1 389
故里飘歌
故里飘歌 2021-01-27 03:49

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

1条回答
  •  离开以前
    2021-01-27 04:15

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

    0 讨论(0)
提交回复
热议问题