Reputation: 4604
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?
Upvotes: 10
Views: 13862
Reputation: 1511
For Drupal objects, or for other frameworks which don't use $, use the following:
console.log(jQuery('body')[0]);
OR (with the old syntax):
jQuery('body');
Upvotes: 0
Reputation: 8855
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.
Upvotes: 15