How to remove all whitespace from string in JQuery?

By Hardik Savani September 5, 2020 Category : Javascript HTML jQuery

Sometimes we require to remove white space from given string. So at that time you can delete spaces from string 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. you can do it from 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,'');





We are Recommending you