Categories
JavaScript Answers

How to log an HTML element as a JavaScript object?

Spread the love

Sometimes, we want to log an HTML element as a JavaScript object.

In this article, we’ll look at how to log an HTML element as a JavaScript object.

How to log an HTML element as a JavaScript object?

To log an HTML element as a JavaScript object, we can use the console.dir method.

For instance, we write

const element = document.documentElement;
console.dir(element);

to get the document element with document.documentElement.

Then we assign that to element and log that with console.dir.

As a result, the properties of element will be displayed in the console.

Conclusion

To log an HTML element as a JavaScript object, we can use the console.dir method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.