javascript - java script i want to add two variables x=y -


what meaning of following syntax

var demop=document.getelementbyid("demo"); demop.innerhtml="x=" + x; 

and "x=" + x;

getelementbyid() method accesses first element specified id.

thus , document.getelementbyid("demo") access element id demo.

the innerhtml sets inner html of element.it used modify document's html on fly.

for example:

<head>  <script type="text/javascript">         function myfunction() {             var x = 100;             var demop = document.getelementbyid("demo")             demop.innerhtml = "x=" + x;         }     </script> </head>  <body> <div id="demo"/> <p>     <a href="#" onclick="myfunction()"> click call function</a> </p> </body> </html> 

in above code, when event fired clicking link,js method myfunction() called.in method,demop contains element id demo.

demop.innerhtml modify demo id , add x=100 in demo div.that demo div changes <div id="demo">x=100</div>


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -