title: Javascript : Close open HTML tags in a string
body: <p>I have a javascript string that has HTML code. I display it and I have attached a read more/less toggler based on the number of words. The problem is, when I shrink the HTML code, it might have open tags, for suppose </p>
  
  <pre><code>&lt;p&gt;A computer is a general purpose device that can be &lt;b&gt;programmed&lt;/b&gt; to carry out a finite set of arithmetic or logical operations&lt;/p&gt;
  </code></pre>
  
  <p>when shrinked becomes</p>
  
  <pre><code>&lt;p&gt;A computer is a general purpose device that can be &lt;b&gt;programmed...more&lt;/p&gt;
  </code></pre>
  
  <p>Because of unclosed bold tag, the following data becomes bold.</p>
  
  <p>I want a javascript solution to close the unclosed tags in a string. Any kind of help is highly appreciated. Thank you all in advance.</p>