How to remove all spaces from string in JQuery?

By Hardik Savani | June 9, 2018 | Category : Javascript jQuery

In this post, I would like to share with you how to remove all white spaces or blank space from a string using jquery.

Actually, we may sometime require to delete all empty spaces from string in jquery javascript. we can easily remove all black space using jquery replace function.

Here i give you very small example with one rich textbox and add button bellow. You have to simple add string on rich text box then click on button it will remove all spaces from added string.

It's very simple example and also i give you demo for this you can see bellow button. You are able to download code for remove spaces using jquery. So let's see bellow example.


<html lang="en">


<title>How to remove all spaces from string in JQuery? -</title>

<script src=""></script>




<h1>How to remove all spaces from string in JQuery? -</h1>

<textarea class="content-text"> have a collection of Example and Demo of IT.


<button>Remove White Space</button>


<script type="text/javascript">


myText = $(".content-text").val();

var remove_space = myText.replace(/ /g,'');






You can also download code and check demo too.

I hope it can help you...

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: