What's the best way to add style ?
Using
id.style.color = "green"
or document.getElementById('id').style.color = "green"
?
What's the best way to add style ?
Using
id.style.color = "green"
or document.getElementById('id').style.color = "green"
?
Use the latter option:
document.getElementById('id').style.color = "green"
See this answer for a good write-up on this issue:
It's generally considered bad practice to omit var, as well as to rely on named elements being visible on window or as globals. Stick to document.getElementById, which is more widely-supported and less ambiguous.