I cannot display a javascript variable to a <p>? -


i don't know wrong code had reference of codes , done cannot display variable pharagraph?

this code on script:

<script type="text/javascript">     var myid = document.getelementbyid('myid').value; //      var scope = 'global';      function testscope() {       var scope = 'local';          function innerfunc() {           return scope;                    }                                 return innerfunc();      }      var answer = testscope();       myid.innerhtml = answer; </script> 

on html

<p id="myid"><!-- no variable displayed --></p> 

what doing wrong?

use document.getelementbyid('myid') instead of document.getelementbyid('myid').value. because <p> element hasn't value property

function checkfunctionscope() {    var myid = document.getelementbyid('myid');    var scope = 'global';      function testscope() {        var scope = 'local';        function innerfunc() {        return scope;      }        return innerfunc();    }      var answer = testscope();      myid.innerhtml = answer;  }    window.onload = checkfunctionscope;
<p id="myid">    <!-- no variable displayed -->  </p>


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -