Using eval() on HTML Text - Javascript Language Basics

Javascript examples for Language Basics:eval

Description

Using eval() on HTML Text

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
window.onload = function () {//  ww  w . j ava2s . c om
    var x = document.getElementById("myP").textContent;
    eval("var e = " + x + ";");
    document.body.innerHTML = e();
}

      </script> 
   </head> 
   <body> 
      <p id="myP">function () { if (5&gt;1) { return 5; } } </p>  
   </body>
</html>

Related Tutorials