Replace text to element string with style - Javascript String

Javascript examples for String:replace

Description

Replace text to element string with style

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <style>

.big{ font-size: 55px;  }

      </style> 
      <script>
function chng(){// w ww  .j a  v  a  2  s . c  o m
    var text = document.getElementById('pText').innerHTML;
    var text2 = text.replace('test','<span class="big">test</span>');
    document.getElementById('pText').innerHTML = text2;
}

      </script> 
   </head> 
   <body> 
      <p id="pText"> this is a test </p> 
      <button onclick="chng()">Try it</button>  
   </body>
</html>

Related Tutorials