2

I have a web page with the element:

<div id='myid'></div>

In chrome dev tools, when I type in the console

document.getElementById('myid')

returns a html element,

<div id='myid'></div>

is there an alternative method I can use to view it and it's properties as a JavaScript object instead rather than a html element?

convert html to javascript

I have seen this post, but all I want to do is get the element, not do any parsing and build something new and ideally in dev tools.

Sebastian Speitel
  • 7,166
  • 2
  • 19
  • 38
apollowebdesigns
  • 658
  • 11
  • 26
  • what does it mean javascript object? `div` equivalent `javascript` object, mean you are mixing `HTML` and `Javascript`. – Vaisakh PS Sep 20 '18 at 13:28
  • no, for example when I use document.getElementById('myid').outerHTML I get a html string returned. I would like to use a method that displays it as a list of elements as an object instead. – apollowebdesigns Sep 20 '18 at 13:34

2 Answers2

8

is there an alternative method I can use to view it and it's properties as a JavaScript object instead rather than a html element?

all I want to do is get the element, not do any parsing and build something new and ideally in dev tools

Yes if you are only interested in the dev tools (console), you can always use console.dir() method, it's made for this:

console.dir(document.getElementById('myid'));

console.dir() method:

Displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

Community
  • 1
  • 1
cнŝdk
  • 31,391
  • 7
  • 56
  • 78
0

Would do something like using the Document Element interface to access the array of attributes / properties.

David
  • 5,882
  • 3
  • 33
  • 44