Is there any advantage to writing out document.getElementById
when you can just use the shorthand Id.something
? I'm interested because I see some code online in my tutorials declaring variable x
equals to document.getElementById
, and then them using that variable, instead of just using the shorthand:
Example:
<code>
var timeDisplay = document.getElementById("time");
timeDisplay.innerHTML = message;
</code>
VS.
<code>
time.innerHTML = message;
</code>