apollowebdesigns
apollowebdesigns

Reputation: 758

convert HTML DOM element to JavaScript Object?

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.

Upvotes: 2

Views: 8968

Answers (2)

Damien Allison
Damien Allison

Reputation: 109

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

Upvotes: 0

cнŝdk
cнŝdk

Reputation: 32145

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.

Upvotes: 8

Related Questions