Dave's Brain

Browse - programming tips - javascript trim for all browsers

Date: 2011feb14
Language: javaScript

Q.  How can I "trim" (remove whitespace characters from the start and end)
a string with javaScript that works in all browsers?

A.  Firefox has a trim() but IE doesn't so nice solution is to use trim()
in jQuery like this:

	str = $.trim(str);

This alone isn't reason enough to use jQuery in a project.
Its pretty easy to write a trim using regular expressions.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: