How to view the properties of an element in the console with pure Javascript?

Asked

Viewed 445 times

1

With jQuery I can see the properties of an element on the console with:

console.log($("elemento"));

For example, if I have the element below:

<input id="nome" type="text" placeholder="Digite aqui">

And I do console.log($("#nome"));, the console shows:

inserir a descrição da imagem aqui

How I get the same result with pure Javascript?

I tried with console.log(document.getElementById("nome"));, but returns only the outerHTML of the element:

inserir a descrição da imagem aqui

  • Use console.dir

  • It worked. What is this console.dir? Haven’t heard of it yet

  • The console.dir in theory should display the properties of an object interactively, but in Chrome the console.log does the same. How the behavior of the object console is not standardized, in each browser works in a different way.

  • I tested on Chrome the console.log and did not show, but the console.dir showed. Anyway, obg! If you want to post a reply, I mark as sure.

1 answer

4


For the Chrome browser, console.dir can be used to visualize the properties of an DOM element. According to the specification of the console.dir, this method should work for all browsers, but in practice the implementation of the console usually vary from browser to browser.

console.log in Firefox for example, allows viewing the properties of an element, whereas in Chrome this does not happen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.