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).
精彩评论