Change CSS styling based on content words - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Span

Description

Change CSS styling based on content words

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <style>

.big{ font-size: 55px;  }

      </style> 
      <script>
function chng(){/*from   www  .j a v  a 2s  . 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