How To Remove All Spaces From String in jQuery

Inside this article we will see that how can we remove white spaces from a string using jquery. This tutorial will give you the idea about remove all spaces from string in jquery.

Article will be super easy to understand and very easy to implement in your code.

For example –

String with space as — Online Web Tutor

String with no space — OnlineWebTutor

We will use jquery concept to remove all spaces from a sting.

Learn More –

Let’s get started.

Create an Application

Create a folder with name remove-space. Create a file index.html into it.

Open index.html and write this complete code into it.


<title>How to remove all spaces from string in JQuery?</title>
<link rel=”stylesheet” href=”">
<script src=”"></script>

<div class=”container” style=”margin-top: 30px;”>
<div class=”row”>
<div class=”col-md-12 offset-md-3 mt-5">
<h4>How to remove all spaces from string in JQuery?</h4>
<div class=”panel panel-primary”>
<div class=”panel-heading”>How to remove all spaces from string in JQuery?</div>
<div class=”panel-body”>
<form class=”form-horizontal” action=”#”>
<div class=”form-group”>
<label class=”control-label col-sm-2" for=”file”>String:</label>
<div class=”col-sm-10">
<input type=”text” class=”form-control” id=”string” name=”string” placeholder=”Enter string…”>
<div class=”form-group”>
<div class=”col-sm-offset-2 col-sm-10">
<button type=”button” class=”btn btn-primary”>Remove space</button>
<div class=”form-group”>
<div class=”col-sm-offset-2 col-sm-10">
<h3 id=”remove-space-string”></h3>
<script type=”text/javascript”>
var myText = $(“#string”).val();
var remove_space = myText.replace(/ /g,’’);


Learn More[…]