Search Results

Search found 1 results on 1 pages for 'vorinowsky'.

Page 1/1 | 1 

  • How to call split(token) on a string that does not contain the token without causing an error?

    - by Vorinowsky
    I have two types of strings as the IDs of elements in my HTML markup: Dates: "april-23" "march-20" and season names: "springtime" "winter" The dates have a dash separating the month and the day. The seasons are a single word with no other tokens. I want to assign the month or the season to a new variable called: time_of_year If I do this: var time_of_year = $(this).attr("id").split('-')[0]; It will work on the months but if I call it on a season name which does not contain the token, will it generate an error? What's the safe way to do this?

    Read the article

1