2

I want to show limited text (50 character) using the jquery . please let me how can I do it. I'm using the following code.

var ta = $('title', item).text().replace(/\(.*?\)/, "");

The out put of this is "Failure to qualify for Africa Cup of Nations could spell sorry end for Eto’o’s international".I want to show only 50 character.

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
user1734190
  • 157
  • 1
  • 2
  • 12
  • better answer : http://stackoverflow.com/questions/4637942/how-can-i-truncate-a-string-in-jquery. – Gowri Oct 16 '12 at 08:02

5 Answers5

3

You can use something like this:

String sOut = $('title', item).text().substring(0,50);

Though I don't know what item is doing there. :|

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
1

Try this:

var ta = $('title', item).text().substring(0,50)
j0nes
  • 8,041
  • 3
  • 37
  • 40
1
var ta = $('title', item).text();
var edited = ta.substring(0,50);

Read More

Above code is created assuming that item is the scope

Or you can write this in one line using Jquery chaining.

var ta = $('title', item).text().substring(0,50);
Techie
  • 44,706
  • 42
  • 157
  • 243
1
if(ta.length > 50){
   ta = ta.substring(0, 47) + '...';
}
Irakli Lekishvili
  • 33,492
  • 33
  • 111
  • 169
0
var ta = $('title', item).text();
ta = ta.substring(0,50);
A. Wolff
  • 74,033
  • 9
  • 94
  • 155
Salil
  • 46,566
  • 21
  • 122
  • 156