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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *