JQuery. trim () function and trim () usage _ jquery-js tutorial

Source: Internet
Author: User
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 ()
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.