简体   繁体   English

将HTML DOM元素转换为JavaScript对象?

[英]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 在chrome开发工具中,当我在控制台中键入时

document.getElementById('myid')

returns a html element, 返回一个html元素,

<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? 有没有一种我可以用来查看它的替代方法,它的属性是JavaScript对象而不是html元素?

convert html to javascript 将html转换成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? 有没有一种我可以用来查看它的替代方法,它的属性是JavaScript对象而不是html元素?

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()方法 ,它是为此而设计的:

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

console.dir() method : console.dir()方法

Displays an interactive list of the properties of the specified JavaScript object. 显示指定JavaScript对象的属性的交互式列表。 The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects. 输出显示为带有显示三角形的层次结构列表,可让您查看子对象的内容。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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