Replace the text of span element with HTML entity - Javascript DOM

Javascript examples for DOM:Element innerText

Description

Replace the text of span element with HTML entity

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(){//w w w  .j  a v  a2s  .co  m
var foo = document.getElementById('foo'),
    bar = document.getElementById('bar');
foo.onclick = function (e) {
    foo.innerHTML = '&euro;!';
    bar.innerText = '&euro;!'
};
    }

      </script> 
   </head> 
   <body> 
      <div id="foo">
         Foo
      </div> 
      <div id="bar">
         Bar
      </div>  
   </body>
</html>

Related Tutorials