Ke.
Ke.

Reputation: 2586

Chrome developer tools - console.log native code JS

I'm trying to follow this tutorial:

https://www.youtube.com/watch?v=2zmUSoVMyRU

And at the beginning he is typing in commands in the console such as

$('a')

which appears to be returning all the a tags in the dom. When I do this on my website, I get

TypeError: $ is not a function(…)

I also get this when running console.log as a command

function Function() { [native code] }

Im wondering is there something I have missed completely with dev tools, or is it that there might be some problem with my website overwriting the console.log function (i use wordpress)?

There is also a comment at the bottom where a user is having a similar problem (undefined errors), but it doesnt seem they resolve it.

Upvotes: 0

Views: 1608

Answers (2)

AlfaTeK
AlfaTeK

Reputation: 7765

A quick alternative on chrome dev tools is just to use:

$$('a')

Just to add an explanation: $('a') is using the jquery library which is a piece of JS you have to include in you site. So it will only work on dev tools if the website has jquery included. In your case it doesn't work because of that.

$$ is something built in on chrome dev tools and it will always work, no mater if jquery is included in your website or not.

About console.log you can't just type 'console.log', you have to use it like this: console.log('log my message');

So it needs to be a function call where you pass a string argument that you want to get printed out on chrome dev tools console

Upvotes: 2

Wasiq Muhammad
Wasiq Muhammad

Reputation: 3118

Use like this.It can show you all the a tags in the dom

$$('a')

Upvotes: 2

Related Questions