How to remove all blank spaces from string using JQuery
In this post, We give you an example, sometimes require the remove all spaces from a string, jquery through easily remove spaces from a string.
sometimes use the trim function to remove space from a string but here all spaces remove from a string, so here used replace function.
See below example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <html> <head> <title>How to remove all blank spaces from string using JQuery? - xpertphp</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <div> <h1>How to remove all blank spaces from string using JQuery? - xpertphp</h1> <input class="txtDescription" name="txtDescription" value="How to remove all blank spaces from string using JQuery? - xpertphp"> <button>Remove</button> </div> <script type="text/javascript"> $("button").click(function(){ var txtDescription = $(".txtDescription").val(); var data = txtDescription.replace(/\s/g, ''); alert(data); //output //HowtoremoveallblankspacesfromstringusingJQuery?-xpertphp }); </script> </body> </html> |
Please follow and like us: