0

I have come across a strange thing which I didn't find any reference for. In JavaScript we use document.getElementById("elem").value to get the value of the element with the id="elem"

But I have seen some material which use elem.value straightway to get the value of the element with the id="elem". Previously I thought its a mistake, but when I use the code it works!!

Is it a valid code? How it works??

Please clarify.

1 Answers1

0

when you using a html form element it like this <input type="text" id="name"> then js collects this input type value usingdocument.getElementById("elem").value