In this tutorial, learn how to remove all white spaces from text using jquery. The short answer is: use replace() of jQuery and mention the space you want to remove. The string may contain extra spaces which you can remove easily with this method.

After removal of all the space from the string. You will get a string whose words are closely placed without single space.

This may not prefer in some situation but helpful in some places. Where you don’t want a single piece of space in the text.

Remove All White Spaces From Text Using jQuery

To remove the white spaces from a string, you have to use jQuery text() first. After you get the string in a variable, you have to use replace() to remove all white spaces.


This is my string.

The above example contains a piece of text and the button with the class name. The string contains spaces after each word. Click the above button to remove all the spaces from text. This generates a new string with no spaces at all.

You may also like read.

Hope, you like this tutorial on how to remove all white spaces from text using jquery. If you have any query regarding the tutorial, please comment below.

Also tell me, which method you are using to remove all whitespace from a string using jQuery.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.