DEV Community

ana
ana

Posted on

Return an element in console

Image description

Do you want see an element that you create in your HTML on console by JS?

It's so easy and simple.
there is no more explain about this, but you should know some small tips about it:

We can do this with using from getElementById() method.
this return one element with specified ID.
you should remember that: your IDs name should be unique.
and you should use "variables name rule" for your IDs name.

Here our answer:

  1. select an element with this method like that:
document.getElementById("demo");
Enter fullscreen mode Exit fullscreen mode
  1. This would return the full HTML element:
<h1 id="demo">Hello world.</h1>
Enter fullscreen mode Exit fullscreen mode
  1. We should write our method in console.log as we know for see it in console:
console.log(document.getElementById("demo"));
Enter fullscreen mode Exit fullscreen mode

Finally, I must mention, these things I said are about "HtmlDom" topic in JS.

Top comments (0)