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.
jQuery.trim(string)
<!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); }); });