I'm currently having a problem. I have a div containing html. But if the html inside the div is too long, I want it to be shortened and three dots added in the end. Now with plain text this would be no problem. With html my problem is this. Lets say i have
<div>
Some <a href="someurl">LinkText</a> and a
<span class="this-class">special formatting that's also <b>bold</b></span>
</div>
Now if i implement this with
$(theSelector).html($(theSelector).html().substring(0,50));
will lead to something like this (I didn't count the exact length ;))
<div>
Some <a href="someurl">LinkText</a> and a
<span class="this-
so i will end up with corrupt html. The easy way to solve this would be just to use the text and not the html but i want to keep the formatting. Can anyone think of a way to nicely shorten this but also close all tags again correctly?