title: Javascript substring with html tags
body: <p>I have searched too much on same topic but not is perfect for what I am looking for.</p>
  
  <p>I have a string like :</p>
  
  <pre><code>var string ='&lt;strong&gt;&lt;span&gt;Hii &lt;/span&gt; &lt;p&gt;this is just a demo &lt;span&gt;string&lt;span&gt;&lt;/p&gt;&lt;/strong&gt;'
  </code></pre>
  
  <p>Now what I want is to substring it with limit with javascript substring function but don't want tags to be cut in middle like for example</p>
  
  <pre><code>&lt;strong&gt;&lt;span&gt;Hii &lt;/span&gt; &lt;p
  </code></pre>
  
  <p>It should be like</p>
  
  <pre><code>&lt;strong&gt;&lt;span&gt;Hii &lt;/span&gt; &lt;p&gt;
  </code></pre>
  
  <p>I am using</p>
  
  <pre><code>string.substr(0,200)
  </code></pre>
  
  <p>string is dynamic variable with html tags</p>