In jquery, you can use the "$.trim()" function to remove spaces before and after a string. This function will remove all whitespace characters (newlines, spaces, and tabs) at the beginning and end of the string. symbol), the syntax is "$.trim(string variable)".
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.
How to remove spaces before and after a string in jquery
In jquery, you can use the $.trim() function to remove whitespace characters at both ends of a string. .
$.trim() function removes 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.
The syntax is:
$.trim( str )
The example is as follows:
<!DOCTYPE html> <html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> </head> <body> <pre id="original">