Use div to display function result - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Use div to display function result

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function showAnswer(){//from w  ww  . java  2  s.co  m
    document.getElementById("ans").innerHTML="This is the answer";
}

      </script> 
   </head> 
   <body> 
      <div id="q">
          This is a question? 
         <button onclick="showAnswer()">Show Answer</button> 
      </div> 
      <div id="ans"> 
      </div>  
   </body>
</html>

Related Tutorials