jQuery.trim( str )Returns: Stringversion deprecated: 3.5
Description: Remove the whitespace from the beginning and end of a string.
-
version added: 1.0jQuery.trim( str )
-
strType: StringThe string to trim.
-
Note: This API has been deprecated in jQuery 3.5; please use the native String.prototype.trim
method instead. Unlike jQuery.trim
, String.prototype.trim
does not work with types other than strings (null
, undefined
, Number
). Make sure that your code is compatible when migrating.
The $.trim()
function removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string. If these whitespace characters occur in the middle of the string, they are preserved.
Examples:
Remove the white spaces at the start and at the end of the string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
|
Demo:
Remove the white spaces at the start and at the end of the string.
1
|
|
Result:
1
|
|