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.