How to use the trim () method in jquery
This article mainly introduces how to use the trim () method in jquery. It is very detailed and has a certain reference value. Friends who are interested must finish it!
In jquery, the trim () method is used to remove white space characters from both ends of the string with the syntax "$.trim (str)"; the trim () method removes all newline characters, spaces (including consecutive spaces), and tabs at the beginning and end of the string.
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 white space characters from both ends of a string.
Syntax:
$.trim (str)
Str parameter: a String type that specifies a string that needs to be stripped of white space characters at both ends.
Note: $.trim () removes all newline characters, spaces (including consecutive spaces) and tabs at the beginning and end of the string. If these white space characters are in the middle of the string, they will be retained and not removed.
Example:
$(function () {var str = "lots of spaces before and after"; $("# original") .html ("Original String:'" + str + "'") $("# trimmed") .html ("$.trim ()'ed:'" + $.trim (str) + "');})
Note: the $.trim () function will be obsolete in jQuery 3.5 and above and can be replaced by JavaScript's native String.prototype.trim.
The above is all the content of the article "how to use the trim () method in jquery". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!