In jquery, the trim() method is used to remove whitespace characters at both ends of the string. The syntax is "$.trim(str)"; the trim() method will remove all whitespace characters at the beginning and end of the string. Newlines, spaces (including consecutive spaces), and tabs.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery trim() method
The trim() method is used to remove whitespace characters at both ends of the string.
Syntax:
$.trim( str )
str parameter: It is a String type and specifies a string that needs to remove whitespace characters at both ends.
Note: $.trim()
will remove all newline characters, spaces (including consecutive spaces) and tab characters at the beginning and end of the string. If these whitespace characters are in the middle of the string, they are retained and not removed.
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> </head> <body> <pre id="original">