JQuery Remove All Unwanted Whitespace From String Example
Hi Guys,
Today,I will explain you how to remove all unwanted whitespace from string in jquery. We will show example jquery remove all unwanted whitespace from string.You can easy remove all unwanted whitespace from string in jquery.
jQuery $.trim() function to remove all spaces (including non-breaking spaces), newlines, and tabs from the beginning and end of the specified string. However, the whitespaces that occur in the middle of the string are preserved.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Remove All White Spaces from a Strings</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function () {
$('#test').keyup(function () {
var text = $.trim($(this).val());
$(".trimmed").html(text);
});
});
</script>
</head>
<body>
<h3>Original String</h3>
<input id="test" type="text" />
<br>
<h3>Trimmed String</h3>
<pre class="trimmed"></pre>
</body>
</html>
It will help you...
- How to Show Loading Spinner in JQuery?
- How to Create Ajax Submit Form Using jQuery?
- How To Get Current Page URL, Path, Host and hash using jQuery?
- How To Get, Set and Delete Div Background Image jQuery?
- Body Background Video Using Vide Jquery Example
- JQuery UI Autocomplete Example
- JQuery Split String By Comma Into Array Example
- Form Validation using Jquery Ajax and PHP 8 MySQL