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.
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery.trim demo</title>
  6. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  7. </head>
  8. <body>
  9. <pre id="original"></pre>
  10. <pre id="trimmed"></pre>
  11. <script>
  12. var str = "     lots of spaces before and after     ";
  13. $( "#original" ).html( "Original String: '" + str +"'");
  14. $( "#trimmed" ).html( "Trimmed String: '" + $.trim(str) +"'");
  15. </script>
  16. </body>
  17. </html>

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Link To This Post/Page

Spread The Word

Add this button to your blog:
JJ Technology Solutions

Blog Archive

Trackers

eXTReMe Tracker
facebook

- Copyright © JJ Technology Solutions - Powered by Source Code Solutions -