0

I have this on my .js file:

let Odiv=document.getElementById("div0");
console.log(Odiv);

And the output is

<div id="div0">"something"</div>

When I'm expecting it to show the DOM element properties. I'm using Chrome. What's happening?

let Odiv = document.getElementById("div0");
console.log(Odiv);
<div id="div0">"something"</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Unnamed10110
  • 107
  • 1
  • 1
  • 6
  • 3
    Use `console.dir()`. – Barmar Apr 21 '20 at 16:57
  • 1
    "What's happening?" Your expectations are incorrect. – Heretic Monkey Apr 21 '20 at 17:01
  • 1
    console.log works in the console. SO's console looks different – mplungjan Apr 21 '20 at 17:02
  • @mplungjan No it doesn't. It shows the DOM tree rather than the properties. – Barmar Apr 21 '20 at 17:03
  • @mplungian [`console.dir` at MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/dir). Namely, "displays an interactive list of the properties of the specified JavaScript object." – Heretic Monkey Apr 21 '20 at 17:04
  • @HereticMonkey Then why sometimes when I refresh the page it shows the DOM object with console.log()?. – Unnamed10110 Apr 21 '20 at 17:04
  • See "Difference between log() and dir()" at [`console.log`](https://developer.mozilla.org/en-US/docs/Web/API/Console/log). – Heretic Monkey Apr 21 '20 at 17:06
  • @Barmar Thank you! That is a useful answer. – Unnamed10110 Apr 21 '20 at 17:06
  • Not sure what you mean. If you're seeing inconsistent behavior with a specific browser's implementation of `console.log`, that sounds like something you should take up with the browser maker. – Heretic Monkey Apr 21 '20 at 17:07
  • @Barmar console.log AND console.dir BOTH show domElement.toString() in stack snippets. Either will show some kind of tree in the actual console. From OP's question it seems obvious he meant here or some other rendering OTHER than the browser console – mplungjan Apr 21 '20 at 17:15
  • @mplungjan I don't think it's obvious at all what the OP meant ("I have this on my .js file" being the most telling). If the OP meant in the snippet, please [edit] the question to make that clear. At that point, the question should probably be migrated to Meta Stack Overflow, since it's about the functioning of Stack Snippets, whose code has not been updated for a long, long time despite canon's having updated the source code. – Heretic Monkey Apr 21 '20 at 17:22
  • @HereticMonkey I agree it was not obvious, but as .dir and log does not show tags in the console, something else was going on – mplungjan Apr 21 '20 at 17:35
  • @mplungjan The question wasn't about stack snippets, it was about the real Chrome console. You added the stack snippet. – Barmar Apr 21 '20 at 17:45
  • 1
    @HereticMonkey There was no stack snippet in the original question, it was added by mplungian in an edit. – Barmar Apr 21 '20 at 17:47
  • @mplungjan The `console.log(Odiv)` shows the tag as described in the OP in Chrome Version 81.0.4044.113 (Official Build) (64-bit) on my Windows 10 box. There's no tree because there are no child elements under the `div` provided (yes there are nodes, but no elements). `console.dir(Odiv)` shows a tree of properties, under `div#div0`. – Heretic Monkey Apr 21 '20 at 17:47
  • @HereticMonkey oh. I am on OS X right now – mplungjan Apr 21 '20 at 18:16

0 Answers0