Browser default global $ function

狂风中的少年 提交于 2020-07-16 05:47:05

问题


I've noticed that there appears to be a global function called $ in some browsers which is NOT jQuery, but I can't seem to find any documentation on it. What is it?

Firefox:

Chrome:


回答1:


Chrome and Firefox dev tools include some useful shortcuts/helpers to manipulate the DOM within the console.

These shortcuts are pretty similar for both: $ for DOM selection, $0-$4 for "last X selections" and more.

For full reference see:

  • Chrome Dev Tools Command Line API - https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference
  • Firefox Web Console Helpers - https://developer.mozilla.org/en-US/docs/Tools/Web_Console/Helpers



回答2:


There is no global $ in browsers.

Some browsers provide a $ in the scope of the Console (if there isn't a global one already).

For example Chrome's documentation says:

$(selector) returns the reference to the first DOM element with the specified CSS selector. This function is an alias for the document.querySelector() function.



来源:https://stackoverflow.com/questions/53554987/browser-default-global-function

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