Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view DOM element when console.log jquery object in webkit

Used to be able to perform a console.log on a jQuery object and Chrome would output the corresponding DOM element like the Elements Tab.

Now it does this:

console.log($('body'));
[<body>, context: #document, selector: "body"]

If you leave out the console.log, and type directly into the console you can get the old behavior:

$('body')
[<body>​…​</body>​]

This is what I want! How do I get it back so I log jQuery objects programmtically and have them return live DOM objects like the elements Tab?

like image 976
Globalz Avatar asked Nov 28 '12 04:11

Globalz


1 Answers

This should do it for you:

console.log($('body')[0]);

The reason being jQuery wraps elements in an array, so you need to access the actual element via an array index.

Or click the little triangle to the left to expand the output so that you can interact with the elements that are printed out.

like image 183
subhaze Avatar answered Sep 23 '22 17:09

subhaze