最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

convert HTML DOM element to JavaScript Object? - Stack Overflow

programmeradmin1浏览0评论

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 equivalent javascript object, mean you are mixing HTML and Javascript. – 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
Add a ment  | 

2 Answers 2

Reset to default 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.

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

发布评论

评论列表(0)

  1. 暂无评论