0

Today a friend of mine showed me a piece of code, and I can't understand how it works.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>prueba</title>
  </head>
  <body>
    <form name="form1">
      <input name="textInput" value="aaaaaa" type="text"><br>
    </form>
    <script>
      console.log(form1.innerHTML); //what's going on here??
      console.log(form1.textInput.value); // and here??
    </script>
  </body>
</html>

I don't know how you can just access an element by typing it's name attribute's value. I've been looking up documentation about the dom in js but I can't find anything similar. Can someone please explain how and why it works?

0 Answers0