Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I console.log a jQuery DOM Element in Chrome?

I used to be able to do console.log(somejQueryObj); and it logged in an array all of the DOM elements that are in the object that I could click and go to the inspector.

Now it does something like this:

[prevObject: p.fn.p.init[1], context: , selector: ".next ()"]

which can confuse many people.

How do I make it so that Chrome logs how it used to log jQuery elements?

Here is a fiddle example


I am in:

Google Chrome 23.0.1271.97 (Official Build 171054) m

like image 907
Naftali Avatar asked Dec 20 '12 14:12

Naftali


2 Answers

Update: I made a jQuery plugin to bring back the old style logging: jquery.chromelog.


You could create a little function to log all elements on one line:

$.fn.log = function() {
  console.log.apply(console, this);
  return this;
};

Usage:

$("...").log();
like image 100
pimvdb Avatar answered Oct 16 '22 17:10

pimvdb


To do it for each element so that you can hover over it, try something like this:

$("div").each(function(){console.log(this)})​
like image 36
lamflam Avatar answered Oct 16 '22 18:10

lamflam