0

I just discovered a feature that I didn't know about to access to input value.

Let's say that I have the following input in my HTML template:

<input type="text" id="myinput" />

Until then, I used to access to the value of the input through the following line:

var myinput = document.getElementById("myinput");
var value = myinput.value;

And this is the solution that I found in every post about this topic. But it seems that (recent?) browsers actually do the first line automatically because I can access to the value of my input directly through:

var value = myinput.value

We can see a working example here: Plunker

It seems fair for the browsers to do that automatically but I cannot find any resource that documentate this feature. Perhaps I didn't search well enough but if anyone can explain this to me, it would be good.

aydinugur
  • 1,208
  • 2
  • 14
  • 21
Alexandre D.
  • 711
  • 1
  • 9
  • 28
  • I think you are looking for this.https://stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript – gusaindpk Nov 15 '17 at 13:53
  • I saw that post but I cannot find any reference to the method allowing to access to the value of an input directly using it id, so without calling `document.getElementById()` method – Alexandre D. Nov 15 '17 at 14:43

0 Answers0