How To Remove Spaces Using JQuery

Websolutionstuff
1 min readDec 30, 2020

--

In this tutorial I will explain you how to remove extra space using jquery, many times we have requirements to remove white space from textbox, or many time users added unnecessary space in field which occupied more space in database.

I am giving you very simple example to remove white space from textbox. In this example I have added one text box to add string and one submit button and you will get output in alertbox.

<html lang="en">
<head>
<title>How to remove spaces using JQuery - websolutionstuff.com</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<div>
<h1>How to remove spaces using JQuery - websolutionstuff.com</h1>
<textarea class="content-text">
This is demo how to remove space using jquery.
</textarea>
<button>Remove Space</button>
</div>
<script type="text/javascript">
$("button").click(function(){
removeText = $(".content-text").val();
var rm_space = removeText.replace(/ /g,'');
alert(rm_space);
});
</script>
</body>
</html>

Read Also : How To Check Email Already Exist Or Not In Laravel

--

--

Websolutionstuff
Websolutionstuff

Written by Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

No responses yet