How to remove spaces before and after a string in jquery

WBOY
Release: 2021-11-23 16:40:02
Original
4357 people have browsed it

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)".

How to remove spaces before and after a string in jquery

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 )
Copy after login

The example is as follows:

    
  

        
Copy after login

        
Copy after login

Output result:

How to remove spaces before and after a string in jquery

Related video tutorials Recommended:jQuery video tutorial

The above is the detailed content of How to remove spaces before and after a string in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!