clock  Mon - Sun 8.00 AM - 8.00 PM
mail  edu@teknowize.com
fb
instagram
play store
pinterest

How To Remove All White Spaces From Text Using jQuery

  Sumit Dey Sarkar
  26 Aug 2022
  JQuery
Imperial Advance Hero Image

How To Remove All White Spaces From Text Using jQuery

In this tutorial we will learn how to remove all white spaces from text using jQuery.

Here we will use jQuery remove function to remove all white spaces from text.

Let's see the example -

How to remove all white spaces from text using jQuery

<html lang="en">

<head>
  <title>How to remove all white spaces from text using jQuery</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>

<body>

  <div>
    <h1>How to remove all white spaces from text using jQuery</h1>
    <textarea class="content-textArea">
  	teknowize.com is a online platform to learn programming.
  </textarea>
    <button class="removeBtn">Click me! to remove spaces</button>
  </div>

  <script type="text/javascript">
    $(".removeBtn").click(function () {
      myText = $(".content-textArea").val();
      var remove_space = myText.replace(/ /g, '');
      alert(remove_space);
    });
  </script>


</body>

</html>