The jQuery. trim () function removes spaces at both ends of a string. Jquerytrim functions are widely used. The following section describes jquery. trim () function and trim () Usage Details. For more information, see jQuery. the trim () function removes spaces at both ends of a string. This function can remove the white spaces at the start and end of the string (until the first non-white string is encountered ). It clears common blank characters including line breaks, spaces, and tabs.
This function is a global jQuery object.
Syntax
JQuery 1.0 adds this static function.
JQuery. trim (str)
Parameters |
Description |
Str |
The String type must remove the white spaces at both ends. |
If the str parameter is not of the string type, this function automatically converts it to a string (generally calls its toString () method ). If the str parameter is null or undefined, an empty string ("") is returned ("").
Return Value
The Return Value of the jQuery. trim () function is of the String type. The return value is the String after the blank strings at both ends are removed.
Example & Description
The following is the jQuery Sample Code related to the jQuery. trim () function to demonstrate the specific usage of the jQuery. trim () function:
// Append the line feed label and the specified HTML content to the current page. function w (html) {document. body. innerHTML + ="
"+ Html;} // double quotation marks are added to both sides of the output to distinguish string boundary w ('"' + $. trim ("CodePlayer") + '"'); //" CodePlayer "// only the consecutive white space characters w ('"' + $. trim ("Code Player") + '"'); //" Code Player "w ('"' + $. trim ("\ r \ n \ t CodePlayer \ t") + '"'); //" CodePlayer "w ('"' + $. trim ("") + '"'); //" w ('"' + $. trim (12) + '"'); //" 12 "w ('"' + $. trim (null) + '"'); //" w ('"' + $. trim (undefined) + '"'); //" w ('"' + $. trim (new Object () + '"'); //" [object Object]"
Trim () usage in jquery
$. Trim ()