What is the difference between Document.getElementById and "element ID"?

Asked

Viewed 29 times

1

I was curious to discover that it is possible to recover an HTML element using its ID as a Javascript variable.

Then the question arose to me: what is the difference between document.getElementById and elementoID and which modes should be used/which situations?

Follow a brief example of what I’m saying:

console.log(divExemplo);
//Mesma coisa!
console.log(document.getElementById('divExemplo'));
<div id="divExemplo"></div>

No answers

Browser other questions tagged

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