How to remove all spaces from string in JQuery?

Jquery

Nicesnippets

1149

03-04-2021


How to remove all spaces from string in JQuery?

Hello Friends,

Now let's see example of how to remove all spaces from string in jquery. We will learn jquery remove all space from string. This tutorial will give you easy and simple way to remove all spaces from string in jquery.

Here i give you very small example with one rich textbox and add button bellow. You have to simple add string on rich text box then click on button it will remove all spaces from added string.

Here I will give you simple example and also i give you demo for this you can see bellow button. You are able to download code for remove spaces using jquery. So let's see bellow example.

Example


<html lang="en">

<head>

<title>How to remove all spaces from string in JQuery? - NiceSnippets.com</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

<style>

body{

background: rgb(216, 232, 215);

}

.container{

background: rgb(247, 228, 220);

margin-top: 14%;

height: 300px;

width: 51%;

border: 3px solid red !important;

}

.container h4{

margin-bottom: 42px;

font-size: 25px;

}

</style>

</head>

<body>

<div class="container text-center border">

<h4 class="mt-5 font-weight-bold">How to remove all spaces from string in JQuery? - NiceSnippets.com</h4>

<textarea class="content-text" cols="55" rows="2">

NiceSnippets.com have a collection of Example and Demo of IT.

</textarea>

<button class="btn btn-primary mx-auto d-block mt-4 ">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>

It will help you....


Recommended Posts