Remove All Spaces from String in JQuery?

Have you ever encountered a situation where you need to remove all spaces from a string using JQuery? In this blog article, we will explore the various methods to remove spaces from a string using JQuery.

Step 1:- Create a HTML Page

<html lang="en">
<head>
    <title>How to remove all spaces from string in JQuery? - Wizbrand</title>  
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>
<body>


<div>
  <h1>How to remove all spaces from string in JQuery? - Wizbrand</h1>
  <textarea class="content-text">
  	Wizbrand have a collection of Example and Demo of IT.
  </textarea>
  <button>Remove White Space</button>
</div>


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


</body>
</html>

Output:-

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x