views:

38

answers:

3

Hello.

Does JavaScript have a way of truncating HTML text without all the headaches of matching tags etc etc?

Thank you.

+1  A: 

There's nothing built-in javascript. There's a jQuery plugin that you might take a look at.

Darin Dimitrov
I have not worked with jQuery yet, is it easy to implement or does it require lots of settings and tweakings?
Francisc
It was easy, thank you.
Francisc
A: 

That's quite challenging.

If you don't have any HTML markup, the following might be useful.

TK
Sadly, it's FULL of HTML markup otherwise it would not be an issue.
Francisc
A: 

Try using the javascript substring or slice string functions, depending on how you want to truncate.

http://www.w3schools.com/jsref/jsref_obj_string.asp

Paul
Thanks, but that doesn't take into consideration the HTML rules.
Francisc