JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 20th, 2008, 11:48 AM
denhamd2 denhamd2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 199 denhamd2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 10 m 55 sec
Reputation Power: 9
Trying to truncate a string in JQuery

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

Reply With Quote
  #2  
Old November 20th, 2008, 02:38 PM
Tukaro's Avatar
Tukaro Tukaro is offline
Standing 3 feet to the left.
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: USA
Posts: 1,435 Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
Send a message via AIM to Tukaro Send a message via MSN to Tukaro
You don't need jQuery to do this. Javascript substring method. I'm not familiar with jQuery, but use their text-editing functions to get the text, apply that, then return it. (Looks like html() and replaceWith(), maybe.)

Now, are you trying to just remove the last letter of anything, or are you trying to remove the initial for the person's last name? If you only expect a last initial to be entered, then you can safely stick with just substring(). If, however, you are worried also about full last names, you'll have to turn to split() and use the first part of the returned array, or, worst case, use regex.
__________________
I'd rather teach you to fish than give you a fish. I reserve the right to also slap you with the fish.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Trying to truncate a string in JQuery

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap