I have a snippet of code here
<div id="pTagId" >some content</div>
<button onclick="console.log(document.getElementById('pTagId').innerHTML);">button1</button>
<button onclick="console.log(pTagId.innerHTML);">button2</button>
In the first button I'm using document.getElementById
to get the tag object.
In the second button I'm directly using pTagId
without document.getElementById
and it also works.
is it reliable to use pTagId
directly without document.getElementById
? If yes what is the need of document.getElementById
?