admin管理员组文章数量:1316538
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.
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.
Share Improve this question edited Sep 20, 2018 at 13:40 Sebastian Speitel 7,3462 gold badges20 silver badges38 bronze badges asked Sep 20, 2018 at 13:22 apollowebdesignsapollowebdesigns 7681 gold badge13 silver badges29 bronze badges 2-
what does it mean javascript object?
div
equivalentjavascript
object, mean you are mixingHTML
andJavascript
. – Vaisakh PS Commented Sep 20, 2018 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 Commented Sep 20, 2018 at 13:34
2 Answers
Reset to default 8is 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.
Would do something like using the Document Element interface to access the array of attributes / properties.
本文标签: convert HTML DOM element to JavaScript ObjectStack Overflow
版权声明:本文标题:convert HTML DOM element to JavaScript Object? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742006126a2411989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论