46

I am poor knowledge in jquery. I have mentioned the script below

var header = $('.time'+col).text();
alert(header);

I got string as "109:00AM" from that how to get first letter such as 1. Could you please help me.

user2310209
  • 992
  • 1
  • 12
  • 27

1 Answers1

110

Try with charAt(0) like

var header = $('.time'+col).text();
alert(header.charAt(0));

You can also use substring like

alert(header.substring(1));

And as @Jai said you can use slice also like

alert(header.slice(0,1));
Switch
  • 14,783
  • 21
  • 69
  • 110
GautamD31
  • 28,552
  • 10
  • 64
  • 85
  • 4
    `.slice(0, 1)` too... – Jai Sep 19 '13 at 06:46
  • 3
    Thanku @Jai I have added that now in my ans – GautamD31 Sep 19 '13 at 06:48
  • That is not me who downvoted it. see i liked your comment. – Jai Sep 19 '13 at 06:56
  • 4
    FYI alert(header.substring(1)) in your post here gives entire string *except* the first character, I think you want alert(header.substring(0,1)); - syntax of substring is (start,end) so you want only the first character it's start at charcter 0 end at character 1 (not including character 1) – Gideon Jul 17 '19 at 18:55