...

View Full Version : Trying to truncate a string in JQuery



denhamd2
11-20-2008, 05:50 PM
Hi,

I have the following code:

<div class="person">John S</div>

Is is possible in JQuery to remove the last letter of the text within the div class "person"?

I'm banging my head off a brick wall trying to figure this out, any help would be greatly appreciated.

Thanks in advance

rangana
11-21-2008, 08:22 AM
$(document).ready(function()
{
var cls='person'; // Name of the class you are referring
$('.'+cls).text($('.'+cls).text().substring(0,$('.'+cls).text().length-1));
});

denhamd2
11-21-2008, 11:16 AM
Something strange is happening, I have 3 <div>'s with this class on it and after applying the code each div now contains the 3 people's names with only the last name with the surname removed. Any ideas on where I might be going wrong?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum