Home Javascript How to remove all whitespace from string in JQuery?

How to remove all whitespace from string in JQuery?

by Shahriar Sagor

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.

Example:

<html lang="en">
<head>
    <title>Jquery - Remove white space from string</title>  
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>
<body>


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


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


</body>
</html>

Read Also : Laravel 8 Mobile Number Verification Tutorial

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

close

You may also like