javascript - getElementById is returning undefined from a paragraph -
i'm trying retrieve value of <p> element "sections" , display in <p> element "ss" using getelementbyid. output 'undefined' when should 2. if use <input> element instead of
element works.
i've spent 6 hours looking answer. haven't found on site relates this.
<body> <table id="solidtable"> <tr> <td><p id="sections"></p></td> <td><p id="ss"></p></td> </tr> </table> script:
<script> document.getelementbyid("sections").innerhtml = 2; y = document.getelementbyid("sections").value; document.getelementbyid("ss").innerhtml = y; </script>
paragraph tags don't have value property. use innerhtml correct value.
change
y = document.getelementbyid("sections").value; to
y = document.getelementbyid("sections").innerhtml; // ^^^^^^^^^
Comments
Post a Comment