Chrome can no longer log inspectable jQuery objects from scripts [duplicate]

随声附和 提交于 2019-12-07 15:26:33

问题


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

In the latest stable Chrome 23.0.1271.101, and Chrome Canary 26.0.1373.0, running the following code from a script:

$(function(){
    console.log( $('body') )
})

Now returns:

[<body>, prevObject: jQuery.fn.jQuery.init[1], context: #document, selector: "body"]

Hovering over this log out does nothing, it is not inspectable.

The interactive console still works, eg, typing:

console.log( $('body') )

Will correctly respond with:

[<body>...</body>]

When the mouse is hovered over the log output it can be inspected, as previous versions of Chrome used to do for scripts.

  • Is there a way to make Chrome log inspectable elements per previous versions of Chrome, and as the interactive consol still does?
  • Is there a newer or older version of Chrome which does not have this bug?

回答1:


To achieve what Chrome previously used to do, append [0] to the function.

As pointed out by JanDvorak, this may not work in all cases, and provide only the first element, but works in some cases.

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

Update

From here, there is a jQuery plugin jquery.chromelog made by pimvdb, which seems the way to go.




回答2:


As a workaround, the inspector in Safari 6.0.2 (7536.26.17) still logs inspectable JQuery objects.



来源:https://stackoverflow.com/questions/14136989/chrome-can-no-longer-log-inspectable-jquery-objects-from-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!