remove white spaces from a string in jQuery

remove white spaces from a string in jQuery

In this post we will give you information about remove white spaces from a string in jQuery. Hear we will give you detail about remove white spaces from a string in jQueryAnd how to use it also give you demo for it if it is necessary.

Use the jQuery $.trim() function


You can use the jQuery $.trim() function to remove all the spaces (including non-breaking spaces), newlines, and tabs from the beginning and end of the specified string.


However, the whitespaces in the middle of the string are preserved. The following example will show you how to remove leading and trailing whitespaces from a string of text.



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Remove White Space from Strings</title>
<script src="https://.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        var myStr = $(".original").text();
        var trimStr = $.trim(myStr);
        $(".trimmed").html(trimStr);
    });
</script>
</head>
<body>
    <h3>Original String</h3>
    <pre >      Paragraph of text with       multiple    white   spaces before and after.       </pre>
    <br>
    <h3>Trimmed String</h3>
    <pre ></pre>
</body>
</html>


 

Hope this and post will helped you for implement remove white spaces from a string in jQuery. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  84  =  90

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US