2

With all the sources and what I normally do to select an element by id, is to use .getElementById("eleID").

But have recently observed that I no longer need to use:

.getElementById("eleID").someMethod

or refence it with a variable:

x = document.getElementById("eleID");
x.someMethod`

But instead can go directly too:

eleID.someMethod

I've searched around but can only find advice on using .getElementById("eleID") and when I first started could not just use eleID.someMethod. I have now tested this in Chrome (and in an extension) and Firefox

I am wondering what has changed or has it changed? And why has this not been more widley discussed

Pavlo
  • 43,301
  • 14
  • 77
  • 113
Jason
  • 779
  • 1
  • 9
  • 30
  • 2
    i thought this syntax was valid for `name` attribute only, not id, maybe the element you are using have the same value for name and id? (it is quite common) – Kaddath Feb 27 '17 at 13:16
  • @Kaddath good point, but no I am not using the name attribute in any of my code – Jason Feb 27 '17 at 13:20

0 Answers0