jQuery Remove All Unwanted Whitespace From String

jQuery Remove All Unwanted Whitespace From String

Remove all whitespace from string jQuery; In this tutorial, you will learn how to remove all whitespace or unwanted whitespace from the given string using jquery.

How to Remove All WhiteSpaces from A String Using jQuery

jQuery $.trim() function is used 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.

See 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 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>                            

Recommended jQuery Tutorial

  1. jQuery | Event MouseUp () By Example
  2. Event jQuery Mouseleave By Example
  3. jQuery Event Mouseenter Example
  4. Event jQuery MouseOver() & MouseOut By Example
  5. keyup jquery event example
  6. Jquery Click() Event Method with E.g.
  7. Event jQuery. Blur By Example
  8. jQuery form submit event with example
  9. keydown function jQuery
  10. List of jQuery Events Handling Methods with examples
  11. Jquery Selector by .class | name | #id | Elements
  12. How to Get the Current Page URL in jQuery
  13. jQuery Ajax Get() Method Example
  14. get radio button checked value jquery by id, name, class
  15. jQuery Set & Get innerWidth & innerHeight Of Html Elements
  16. jQuery Get Data Text, Id, Attribute Value By Example
  17. Set data attribute value jquery
  18. select multiple class in jquery
  19. How to Remove Attribute Of Html Elements In jQuery
  20. How to Checked Unchecked Checkbox Using jQuery
  21. jQuery removeClass & addClass On Button Click By E.g.

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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