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">
<head>
    <title>How to Remove Spaces using jQuery - techsolutionstuff.com</title>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>

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


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


</body>
</html>

 


You might also like:

RECOMMENDED POSTS

FEATURE POSTS