jQuery.trim()
**DEPRECATED in Version 3.5**
JQ Home <<
Utilities <<
jQuery.trim()
String trimming.
Description
The jQuery.trim()
jQuery General utility method, removes whitespace from the beginning and end of a string.
Shorthand version $.trim()
- Only removes whitespace from start and end of strings.
This method was deprecated in jQuery 3.5.
Syntax
Signature | Description |
---|---|
jQuery.trim( str ) | Remove whitespace from the beginning and end of a string. |
Parameters
Parameter | Description | Type |
---|---|---|
str | The string to trim. | String |
Return
A String
object.
jQuery.trim( str )
Example
Utilities << Top
Remove whitespace from the beginning and end of a string.
In the example below when we press the button the first time we create a variable and display it before and after trimming within some preformatted text.
$(function(){
$('#btn3').one('click', function(){
var ourString = ' A stitch in time saves nine. ';
$('#div3').append( '<pre>+++' + ourString + '+++' + '</pre>'<br>');
$('#div3').append( '<pre>+++' + $.trim( ourString ) + '+++' + '</pre><br>');
});
});
div3. Some initial text.
Related Tutorials
jQuery Intermediate Tutorials - Lesson 9 - jQuery General Utilities