- Back to Home »
- HTML , jQuery »
Posted by : Jebastin
Tuesday, 21 January 2014
The $.trim() function removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string. If these whitespace characters occur in the middle of the string, they are preserved.
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>jQuery.trim demo</title>
- <script src="//code.jquery.com/jquery-1.10.2.js"></script>
- </head>
- <body>
- <pre id="original"></pre>
- <pre id="trimmed"></pre>
- <script>
- var str = " lots of spaces before and after ";
- $( "#original" ).html( "Original String: '" + str +"'");
- $( "#trimmed" ).html( "Trimmed String: '" + $.trim(str) +"'");
- </script>
- </body>
- </html>