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.
“jquery string get first character” Code Answer'svar str="Hello Folks!"
Get the First Letter of the String You should use the charAt() method, at index 0, to select the first character of the string. NOTE: charAt is preferable than using [ ] (bracket notation) as str. charAt(0) returns an empty string ( '' ) for str = '' instead of undefined in case of ''[0] .
To get the first and last characters of a string, access the string at the first and last indexes. For example, str[0] returns the first character, whereas str[str. length - 1] returns the last character of the string.
You can use charAt to get the first letter. var x = 'some text'; alert(x. charAt(0)); If you're using jQuery and have a textbox with id="firstName" you can access the first letter in the following way.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With