tags:

views:

31

answers:

1

Hello..

I have a WYSIWYG TEXT EDITOR contained in ID = 'bunchofstuff', which contains text with a bunch of HTML (all types of tags).

Example:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean consectetuer. Etiam venenatis.

Using JQUERY,

  • Part 1 - How can I get the text in the ID bunchofstuff, strip out all the HTML so I just have TEXT
  • Part 2 - If it's over 40 characters of text, display the 40 characters with a ... at the end
  • Part 3 - If it's under 40 characters, just show the line of text w/o ... trailing at the end.

Thanks for the ideas.

+1  A: 
var text = $('bunchofstuff').text();
if (text.length) > 40) {
  text = text.substring(0, 37) + '...';
}
alert(text);
Annie
This doesn't strip out the HTML tags
AnApprentice
It depends if bunchofstuff refers to the textarea or the WYSIWYG div.
Matchu
nobosh, the .text() call should strip out the HTML tags.
Annie