Why can I use jQuery syntax in the Chrome JS console if jQuery is not loaded on the current page?

I thought that you first need to load the jQuery source to use $ for the target elements. I was on a webpage that does not even contain any scripts, but somehow I was able to run $('body') inside the Javascript console, and Chrome successfully returned its value.

Why didn't I get a syntax error like 'undefined token'? Thanks.

+4
source share
2 answers

Prior to that, Chrome had an alias document.getElementById with the variable $ .

Recently (possibly in the release of Chrome 23), it has been changed to the alias document.querySelector .

So your code is equivalent to document.querySelector('body') .

+10
source

As mentioned in the comments of @Shmiddty, this is most likely due to the plugin you installed ...

You can find out by launching the developer tools, select “Sources” and look in the “Sources and Content Scripting” panel - does it look suspiciously like jQuery somewhere there?

0
source

All Articles