Some days back, one of my team members came to me saying he need a function which is capable of remove the html tags using javascript. I mean if we pass “<span style=’mystyle’> this is demo </span>” this string to the function. It supposes to return only “This is demo” and the main thing is with having no formatting at all, Just the simple text between tags.
So, Initially I make it happen using regular expression but the strategy fails when some think like &nbsp; comes in. after snatching my hairs, putting some hard hand on the keyboard just before the moment I go for suicide J the following code did the trick.
 
       function removeHTMLTags(htmlString){
        if(htmlString){
          var mydiv = document.createElement("div");
           mydiv.innerHTML = htmlString;
 
            if (document.all// IE Stuff
            {
                return mydiv.innerText;
               
            }   
            else // Mozilla does not work with innerText
            {
                return mydiv.textContent;
            }                           
      }
   }