You can do it using the trim function of JavaScript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example to Remove White Space from Strings Using JavaScript</title> <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ var myStr = $(".original").text(); var trimStr = $.trim(myStr); $(".trimmed").html(trimStr); }); </script> </head> <body> <h3>Here is the Original String</h3> <pre class="original"> This is a Paragraph of text with multiple white spaces before and after. </pre> <br/> <h3>Trimmed String</h3> <pre class="trimmed"></pre> </body> </html> |
Likes
(0)Dislikes
(0)


If not for your writing this topic could be very colunovted and oblique.