admin管理员组文章数量:1323707
I am just messing around and am logging out a div that I have selected with standard javascript but that I have executed inside a jQuery document.ready(fn) block.
$(document).ready(function(){
console.log(document.getElementById( 'blah' ));
})
I'm really interested to know why sometimes I get...
<div id="blah"></div>
And other times I get...
Seems to log differently randomly.
I am just messing around and am logging out a div that I have selected with standard javascript but that I have executed inside a jQuery document.ready(fn) block.
$(document).ready(function(){
console.log(document.getElementById( 'blah' ));
})
I'm really interested to know why sometimes I get...
<div id="blah"></div>
And other times I get...
Seems to log differently randomly.
Share Improve this question edited Dec 1, 2014 at 8:38 Chris Hayes 12.1k4 gold badges34 silver badges47 bronze badges asked Dec 1, 2014 at 5:01 ExitosExitos 29.8k39 gold badges128 silver badges178 bronze badges 4- 1 Can you provide the exact code and/or fiddles to demonstrate this behavior? Also are you seeing it consistently across multiple browsers? – 1252748 Commented Dec 1, 2014 at 5:10
- I'm just writing it out using a console.log you can see it displayed... – Exitos Commented Dec 1, 2014 at 5:23
- 1 You've got to tell us which web browser this question is about. – Chris Martin Commented Dec 1, 2014 at 5:28
- I removed the jquery tag - this question would be exactly the same without jQuery. – Chris Hayes Commented Dec 1, 2014 at 5:44
2 Answers
Reset to default 2This does appear to be random, at least in Chrome. If you want to force it one way or another in the Chrome console you can use console.dir
and console.dirxml
.
console.dirxml
will force the output to be like your first example, in xml formatconsole.dir
will output like your second example, in object notation.
More examples of console mands in Chrome: https://developer.chrome./devtools/docs/console-api
Edit: dirxml
also works in Internet Explorer 11 and later but not in Firefox though this shouldn't be an issue as Firefox outputs elements in XML format.
Each environment decides on how to present objects:
FireFox/Firebug: <div id="blah">
IE/Developer tools: [object HTMLDivElement]
本文标签:
版权声明:本文标题:javascript - Why does console.log(document.getElementById( 'blah' ))) give different log messages in Chrome? - S 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742130287a2422127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论