Remove Whitespace from String using JQuery
July 11, 2018
JQuery provides trim method We can use the jQuery $.trim() function to remove all spaces (including non-breaking spaces), newlines, and tabs from the beginning and end of the specified string. However the whitespaces occurs in the middle of the string are preserved. The trim() method does not change the original string.
Trim function only removes spaces from starting and end of the string. If there are any space between middle of the statement that is ignored.
Below example will show you how to remove leading and trailing whitespaces from a string of text.
var spacestr = ” Hello Webtechsource “;
var withoutspacestr = $.trim(spacestr);
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face – we are here to solve your problems.