Use of document.getElementById in JavaScript

后端 未结 7 1016
后悔当初
后悔当初 2021-02-06 08:31

Can someone explain what the document.getElementById(\"demo\") line does in the example below?

I understand getElementById gets the id of demo but the id is

7条回答
  •  旧巷少年郎
    2021-02-06 09:16

    Consider

     var x = document.getElementById("age");
    

    Here x is the element with id="age".

    Now look at the following line

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

    this means you are getting the value of the element which has id="age"

提交回复
热议问题