How to Remove All Whitespace from String in JQuery?

By Hardik Savani November 5, 2023 Category : jQuery

Hey,

In this quick guide, we will teach you jquery remove all whitespace from string. If you have a question about remove space from string jquery then I will give a simple example with a solution. We will use jquery remove whitespace from string. In this article, we will implement a remove whitespace from string using 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.

Example:

index.html

<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 myString = "This is my site.";

var newString = myString.replace(/ /g,'');

console.log(newString);

</script>


</body>

</html>

Output:

Thisismysite.

I hope it can help you...

Tags :
Shares