title: How to remove only html tags in a string using javascript
body: <p>I want to remove html tags from given string using javascript. I looked into current approaches but there are some unsolved problems occured with them.</p>
  
  <p>Current solutions</p>
  
  <p>(1) Using javascript, creating virtual div tag and get the text</p>
  
  <pre><code>  function remove_tags(html)
    {
         var tmp = document.createElement("DIV");
         tmp.innerHTML = html; 
         return tmp.textContent||tmp.innerText; 
    }
  </code></pre>
  
  <p>(2) Using regex</p>
  
  <pre><code>  function remove_tags(html)
    {
         return html.replace(/&lt;(?:.|\n)*?&gt;/gm, '');
    }
  </code></pre>
  
  <p>(3) Using JQuery</p>
  
  <pre><code>  function remove_tags(html)
    {
         return jQuery(html).text();
    }
  </code></pre>
  
  <p>These three solutions are working correctly, but if the string is like this</p>
  
  <pre><code>  &lt;div&gt; hello &lt;hi all !&gt; &lt;/div&gt;
  </code></pre>
  
  <p>stripped string is like 
        <code>hello</code> . But I need only remove html tags only. like <code>hello &lt;hi all !&gt;</code></p>
  
  <p><strong>Edited: Background is, I want to remove all the user input html tags for a particular text area. But I want to allow users to enter <code>&lt;hi all&gt;</code> kind of text. In current approach, its remove any content which include within &lt;>.</strong></p>