How To Remove All White Spaces From Text Using jQuery

AuthorSumit Dey Sarkar

Pubish Date26 Aug 2022

categoryJQuery

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>
Comments 0

Leave a comment