4

I thought one has to have jQuery source loaded first in order to use $ to target elements. I was on a webpage that doesn't even include 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.

2 Answers2

10

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

Recently (probably on Chrome 23 release), it has been changed to an alias to document.querySelector.

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

Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
0

As already alluded to in the comments by @Shmiddty, it is likely due to a plugin you have installed...

You can find out by running developer tools, select 'Sources' and look at both the Sources and Content Scripts panes - is something suspiciously like jQuery in there somewhere?

babelmonk
  • 134
  • 6