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,401
  • 14
  • 78
  • 121
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
  • 75,209
  • 33
  • 136
  • 171
1

Try this:

var ta = $('title', item).text().substring(0,50)
j0nes
  • 7,853
  • 3
  • 35
  • 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
  • 43,532
  • 40
  • 152
  • 238
1
if(ta.length > 50){
   ta = ta.substring(0, 47) + '...';
}
Irakli Lekishvili
  • 32,032
  • 33
  • 109
  • 169
0
var ta = $('title', item).text();
ta = ta.substring(0,50);
A. Wolff
  • 73,242
  • 9
  • 90
  • 149
Salil
  • 45,112
  • 20
  • 117
  • 151