简体   繁体   中英

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.

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.

类似于使用Document [Element][1]接口访问属性/属性数组:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM