Reputation: 43
My code:
monthName = $("#StartDateMonth option:selected").text();
console.log(monthName, monthName.substring(0,3), 'December'.substring(0,3));
Return:
December
<nothing>
Dec
Why this ridiculous thing occur? My browser: Chrome - Ubuntu
Upvotes: 1
Views: 2237
Reputation:
It must be the spaces in the result of .text()
. You can trim it before calling substring
.
Example:
monthName = $.trim($("#StartDateMonth option:selected").text());
console.log(monthName, monthName.substring(0,3), 'December'.substring(0,3));
Upvotes: 1