title: Javascript allow only specific HTML tags
body: <p>I have a long HTML string, and I would like to parse it to allow only certain html tags to pass through.</p>
  
  <p>The allowed tags are bold, italics, underline, paragraph, ordered list, and unordered list.</p>
  
  <p>These tags and their corresponding text should be returned. All other tags should be removed, and only the innerHTML should be left for those.</p>
  
  <p>For the following inputs, the outputs should be as such: </p>
  
  <p>Input: <code>&lt;p&gt;There is some &lt;u&gt;text&lt;/u&gt; here&lt;/p&gt;</code> 
  Output: <code>&lt;p&gt;There is some &lt;u&gt;text&lt;/u&gt; here&lt;/p&gt;</code></p>
  
  <p>Input: <code>&lt;span style="color: rgb(34, 34, 34); font-family: arial; font-size: small;"&gt;text here&lt;/span&gt;</code> 
  Output: text here</p>
  
  <p>Input: <code>&lt;div&gt;Combo of &lt;b&gt;allowed&lt;/b&gt; tag and &lt;i&gt;disallowed&lt;/i&gt; tag&lt;/div&gt;</code>
  Output: <code>Combo of &lt;b&gt;allowed&lt;/b&gt; tag and &lt;i&gt;disallowed&lt;/i&gt; tag</code></p>
  
  <p>I have looked at this similar question: <a href="https://stackoverflow.com/questions/9494143/regex-to-allow-only-set-of-html-tags-and-attributes">Regex to allow only set of HTML Tags and Attributes</a>. But, I was wondering how you would do it in Javascript?
  I am currently iterating through the html and doing a search for the allowed tags like this: </p>
  
  <pre><code>var htmlString = "&lt;p&gt;There is some &lt;u&gt;text&lt;/u&gt; here&lt;/p&gt;";
  var allowedTags = ["&lt;b&gt;", "&lt;i&gt;", "&lt;u&gt;", "&lt;p&gt;", "&lt;ol&gt;", "&lt;ul&gt;"];
  for (i = 0, len = allowedTags.length; i &lt; len; i++) {
      var ind = htmlString.indexOf(allowedTags[i]);
  }
  </code></pre>
  
  <p>But this doesn't work, especially if you have multiple html tags in a string. 
  Much appreciation for your help!</p>