How To Remove Spaces Using JQuery

In this post, I will explain how to remove spaces using jQuery. Sometimes, we need to eliminate white spaces from textboxes or user input, which can lead to unnecessary data in the database. I'll demonstrate an example of removing white spaces from a textbox using jQuery.

This example includes a textbox for input and a submit button, and you will receive the output in an alert box. jQuery will help you remove all the white spaces from the input string.

So, let's see remove blank space from string jQuery, strip spaces javascript, how to trim whitespace using jQuery.

<html lang="en">
    <title>How to Remove Spaces using jQuery -</title>  
    <script src=""></script>

  <h1>How to Remove Spaces using jQuery -</h1>
  <textarea class="content-text">
  	This is example   how to remove space using jquery.
  <button>Remove Space</button>

<script type="text/javascript">
  	  removeText = $(".content-text").val();
      var rm_space = removeText.replace(/ /g,'');



You might also like:


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.