Introduction to using jquery $.trim of method


$. Trim (STR)

Return: string;

Remove Spaces at the beginning and end of a string.

Example:

Here’s the error code:


<input type="text" name="" id="results" value=""/>

var content = $('#content').val();
if(content.trim() == '')
alert(' empty ');

The above method does not report errors in firefox, but it does report errors in ie

Therefore, the following format should be written:


<input type="text" name="" id="results" value=""/>

var content = $('#results').val();
if($.trim(content) == '')
alert(' empty ');

or


var content = $('#content').val();
if(jQuery.trim(content) == '')
alert(' empty ');