开发者

Safari/WebKit's console.log DOM node as object?

开发者 https://www.devze.com 2023-04-13 00:09 出处:网络
This is something that\'s been driving me nuts for a while. When I console.log a DOM node (returned by example from document.getElementById), it appears as an interactive html element, as it would app

This is something that's been driving me nuts for a while. When I console.log a DOM node (returned by example from document.getElementById), it appears as an interactive html element, as it would appear on the "Elements" tab.

This can be handy for sure, but there are times when I just wan开发者_运维技巧t to be able to expand the object and see all of its properties, like I can do for every other kind of object I log to the console.

Is there any way I can get a DOM node to display in the console as a regular object??


Use console.dir instead of console.log.

console.log( document.body );
<body class="question-page">...</body>

console.dir( document.body );
> HTMLBodyElement
    aLink: ""
    attributes: NamedNodeMap
    background: ""
    ...

From the Firebug docs:

console.dir(object)

Prints an interactive listing of all properties of the object. This looks identical to the view that you would see in the DOM tab.

Chrome supports console.dir as well, as shown here (not shown as a property of console, but it is available).

Safari/WebKit's console.log DOM node as object?

0

精彩评论

暂无评论...
验证码 换一张
取 消