JQuery remove spaces between words
How to remove whitespace from string in jquery
In this article we demonstrate how to remove Spaces from the string (leading and trailling spaces) by using Jquery trim method with the help of live example. The following JQuery Script can be used to remove spaces from the sequence of character.
Jquery remove spaces example
<!DOCTYPE html> <html> <head> <link href="http://freeonlinecompiler.ptutorial.com/ css/bootstrap.min.css" rel="stylesheet"> <script src="http://freeonlinecompiler.ptutorial.com/ js/jquery.min.js"></script> <script> $(document).ready(function (e) { $('#kk').click(function () { var z = $.trim($('#uk').val()); if(z==''){ $('#uk').css("border-color","red"); alert("Please enter first"); }else{ $('#uk').css("border-color","green"); $("#divData").text(z); return false; } }) }); </script> </head> <body> <div class="container-fluid"> <div class="col-sm-4"></div> <div class="col-sm-4"> <h4>Remove leading spaces and trailing spaces </h4> <div class="form-group"> <label>Enter Name *</label> <input class="form-control" type="text" id="uk" name="kk1"> </div> <input type="submit" id="kk" class="btn btn-danger" value="Check"> <div id="divData"></div> </div> <div class="col-sm-4"></div> </div> </body> </html>