2

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.

2
  • what does it mean javascript object? div equivalent javascript object, mean you are mixing HTML and Javascript. 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. Commented Sep 20, 2018 at 13:34

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.