Extract the text out of HTML string - Javascript String Operation

Javascript examples for String Operation:String HTML

Description

Extract the text out of HTML string

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script type="text/javascript">
function extractContent(value){/*w  w  w. j  a va2  s  . c o  m*/
        var div = document.createElement('div')
        div.innerHTML=value;
        var text= div.textContent;
        return text;
}
window.onload=function()
{
   console.log(extractContent("<p>Hello</p><a href='http://w3c.org'>W3C</a>"));
};

      </script>  
   </body>
</html>

Related Tutorials