This works fine in FireFox:
$(“#listname”).val().trim()
But in safari it errors: $(“#listname”).val().trim() while this does work, $(“#listname”).val()
Why is that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no intrinsic
trimfunction on strings. jQuery does define$.trim, but you use it like this:E.g., you pass the string into it, rather than calling it from a property on String.
And as the other answerer mentioned, if you like, you can add it to all Strings (although I’d leverage jQuery’s function rather than doing my own regexs, because of Unicode vagaries in browsers):
I’ve used a named function there (I always use named functions), but you could use fewer lines of code if you’re not bothered: