Learn jQuery

jQuery trim()

jQuery trim() is used to remove the whitespace from the beginning and end of a string.

It will not remove whitespace characters occur in the middle of the string.

Syntax

jQuery.trim(string)

Remove the whitespaces at the start and at the end of the string using jQuery.

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery trim() Example </title>
</head>
<p>    Hi All, how are you       </p>
<button>Remove whitespace</button>
<div></div>
</html>
Javascript
$(document).ready(function(){
$("button").click(function(){
var str=$('p').html();
var trimedstr=jQuery.trim(str);
$("div").html('Trimed string :'+trimedstr);
}); 
});