0

What's the best way to add style ?

Using

id.style.color = "green" or document.getElementById('id').style.color = "green" ?

Swarovski
  • 581
  • 2
  • 8
  • 25

1 Answers1

1

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.

Community
  • 1
  • 1
Anton Strogonoff
  • 32,294
  • 8
  • 53
  • 61