How to remove all whitespace from string in JQuery?

Today now in this post i will show you How to remove all whitespace from string in JQuery? Sometimes we must need to remove the white space from the given string. So at that times we can delete the spaces from string by using replace() of core php. replace() will help to replace your blank space or empty space or extra space or trailing space from string that way we can remove.

We can do this from the bellow example.


<html lang="en">
    <title>Jquery - Remove white space from string</title>  
    <script src=""></script>

<div class="mytext">
  This   is  my site.

<script type="text/javascript">
      var myText = $(".mytext").text();
      var newMyText = myText.replace(/ /g,'');


Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →