2

I have found that I don't need use document.getElementById to get the an element, I can use like this:

<div id="observer1"></div>

Then i can access like a variable:

console.log(observer1);

Why should I use the document.getElementById if I can access directly? I had never heard that this was possible, is there any side-effect, is this supported in all browsers?

Thank you.

1 Answers1

-3

Using console.log(observer1) just outputs the whole element. You have no control over it. You can't adjust properties, attributes or assign values. There is almost no practical use for doing it that way.

Difster
  • 3,264
  • 2
  • 22
  • 32