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
- jQuery | Event MouseUp () By Example
- Event jQuery Mouseleave By Example
- jQuery Event Mouseenter Example
- Event jQuery MouseOver() & MouseOut By Example
- keyup jquery event example
- Jquery Click() Event Method with E.g.
- Event jQuery. Blur By Example
- jQuery form submit event with example
- keydown function jQuery
- List of jQuery Events Handling Methods with examples
- Jquery Selector by .class | name | #id | Elements
- How to Get the Current Page URL in jQuery
- jQuery Ajax Get() Method Example
- get radio button checked value jquery by id, name, class
- jQuery Set & Get innerWidth & innerHeight Of Html Elements
- jQuery Get Data Text, Id, Attribute Value By Example
- Set data attribute value jquery
- select multiple class in jquery
- How to Remove Attribute Of Html Elements In jQuery
- How to Checked Unchecked Checkbox Using jQuery
- jQuery removeClass & addClass On Button Click By E.g.